Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
%clientname%.cmd

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.