JSI Tip 6280. How can I add the %ComputerName% to the CMD prompt?

I use a KVM switch to access the multiple servers and my desktop. Sometimes, it is difficult to determine which computer I am viewing. I have implemented tip 2001/1271, but My Computer is often hidden behind an open CMD window, as I use CMD.EXE frequently.

In tip 2373, I described using the AutoRun Value Name to run a command when a CMD window is opened. If you have AutoRun set to

 prompt %computername%$S$P$G

 it will set the prompt to be:

ComputerName CurrentDriveAndPathGreaterThanSymbol

On my desktop computer, the CMD window opens with the following prompt:

JSI005 C:\>

On my Windows XP computer, the CMD window opens with:

JSI007 C:\Documents and Settings\Jennifer>

I have scripted CMDPrompt.bat to allow you to set the AutoRun Value Name to prompt %computername%$S$P$G, using a REG_EXPAND_SZ data type. The syntax for using CMDPrompt.bat is:

CMDPrompt \[C|U\]

If run with no parameters, or the U parameter, CMDPromt.bat sets the AutoRun Value Name at HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor.

If run with the C parameter, CMDPromt.bat sets the AutoRun Value Name at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor.

NOTE: If  AutoRun is NOT NUL at

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor, it is used. If it is missing or NUL, AutoRun at

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor is used.

CMDPrompt.bat contains:

@echo off
set UC=U
if \{%1\}

\{\} goto OK if /i \{%1\}

\{U\} set UC=U&goto OK if /i \{%1\}

\{C\} set UC=C&goto OK @echo Syntax: CMPrompt \[C^|U\] endlocal goto :EOF :OK @echo REGEDIT4>%TEMP%\CMDPrompt.reg @echo.>>%TEMP%\CMDPrompt.reg if "%UC%"

"C" goto computer @echo \[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor\]>>%TEMP%\CMDPrompt.reg goto common :computer @echo \[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\]>>%TEMP%\CMDPrompt.reg :common @echo "AutoRun"=->>%TEMP%\CMDPrompt.reg @echo "AutoRun"=hex(2):70,72,6f,6d,70,74,20,25,63,6f,6d,70,75,74,65,72,6e,61,6d,65,\>>%TEMP%\CMDPrompt.reg @echo ^ ^ 25,24,53,24,50,24,47,00>>%TEMP%\CMDPrompt.reg @echo.>>%TEMP%\CMDPrompt.reg regedit /s %TEMP%\CMDPrompt.reg del /q %TEMP%\CMDPrompt.reg endlocal
To run CMDPromt on every computer, use How do I remotely execute a program or script on 'all' computers in my Windows 2000 domain?

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.