Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a user logon script. I want to install printers based on hostname. Inside this folder \domain.local\SYSVOL\domain.local\Policies{DF3F608C-8D78-934F-B79F-1965F3C4409B}\User\Scripts\Logon

I have cmd files for each host/workstation and the logon.cmd.

Terminal Servers are honoring the environment variable %clientname% but the workstations are not.

Relevant area of logon.cmd

rem Delete all existing printer connections
c:\windows\system32\con2prt.exe /f

rem Call workstation specific script for connecting to printers

Excerpt from clientname.cmdL:

rundll32 printui,PrintUIEntry /in /n\\fileserv\PhaserPS
rundll32 printui,PrintUIEntry /in  /n\\fileserv\CanonIR
rundll32 printui,PrintUIEntry /y  /n\\fileserv\CanonIR
share|improve this question

The variable %CLIENTNAME% doesn't exist unless you have connected to a computer through RDP. You should probably be calling %COMPUTERNAME% instead.

You could specify a different script for the terminal server that uses %CLIENTNAME%. Or you can write a conditional in your script that will use %CLIENTNAME% if it is present, and if it isn't then try %COMPUTERNAME%.

share|improve this answer
Yes %COMPUTERNAME% is what I was missing. Thanks. – Malocchio Jan 17 '11 at 22:57

Zoredache has it right. As an aside, if you're looking to check if a variable is empty, you can do the following:

if not "%CLIENTNAME%"=="" echo all your code goes here

If you leave out the quotes, the batch interpret will just see "if not == echo all your..." and throw an error.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.