Question : %clientname% environment variable not present at login script on windows server 2008 TS

Hi there,

I have a strange problem here on my new Windows server 2008 Standard with terminal services.
I have a script to add printers in association with the clientname (it works correctly on my 2k3 TS for over 2 years now)

But on my new 2k8 server, I can't get the %clientname% variable at logon.

I've made some testing by using a batch file with the command "Set"  in User Login script by GPO and then running the same command in the user Session :

here are the results :

Login script :


C:\Windows>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\rana02\AppData\Roaming
CLASSPATH=.;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
COMPUTERNAME=SAPP4
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=Z:
HOMEPATH=\
HOMESHARE=\\sficetu1\UGestion$\rana02
Image=\\sapp4\Profiles$\Users
ImageInstall=\\sapp4\Profiles$\UserInstall
LOCALAPPDATA=C:\Users\rana02\AppData\Local
LOGONSERVER=\\SDC2
NUMBER_OF_PROCESSORS=8
OS=Windows_NT
Path=\\UQAT.PRIV\SysVol\UQAT.PRIV\Policies\{2DB4072B-1FA1-4442-8365-B79B386F5DF2
}\User\Scripts\Logon;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\
Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSyst
em\;C:\Program Files\SAS\SharedFiles(32)\Formats;C:\Program Files (x86)\Druide\A
ntidote;C:\PROGRA~2\Druide\Antidote
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 23 Stepping 6, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=1706
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
PROMPT=$P$G
PUBLIC=C:\Users\Public
QTJAVA=C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
SEE_MASK_NOZONECHECKS=1
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\rana02\AppData\Local\Temp
TKPATHX8664=C:\Program Files\SAS\SharedFiles\ICU
TMP=C:\Users\rana02\AppData\Local\Temp
USERDNSDOMAIN=UQAT.PRIV
USERDOMAIN=UQAT
USERNAME=rana02
USERPROFILE=C:\Users\rana02
windir=C:\Windows

C:\Windows>pause
Appuyez sur une touche pour continuer...


Batch file manually executed in the user Session :

C:\Windows>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\rana02\AppData\Roaming
CLASSPATH=.;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
CLIENTNAME=RNDEP
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
COMPUTERNAME=SAPP4
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=Z:
HOMEPATH=\
HOMESHARE=\\sficetu1\UGestion$\rana02
Image=\\sapp4\Profiles$\Users
ImageInstall=\\sapp4\Profiles$\UserInstall
LOCALAPPDATA=C:\Users\rana02\AppData\Local
LOGONSERVER=\\SDC2
NUMBER_OF_PROCESSORS=8
OS=Windows_NT
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program F
iles\SAS\SharedFiles(32)\Formats;C:\Program Files (x86)\Druide\Antidote;C:\PROGR
A~2\Druide\Antidote
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 23 Stepping 6, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=1706
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
PROMPT=$P$G
PUBLIC=C:\Users\Public
QTJAVA=C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
SESSIONNAME=RDP-Tcp#0
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\rana02\AppData\Local\Temp\2
TKPATHX8664=C:\Program Files\SAS\SharedFiles\ICU
TMP=C:\Users\rana02\AppData\Local\Temp\2
USERDNSDOMAIN=UQAT.PRIV
USERDOMAIN=UQAT
USERNAME=rana02
USERPROFILE=C:\Users\rana02
windir=C:\Windows

C:\Windows>pause
Appuyez sur une touche pour continuer...

as you can see, the %clientname% returns my computer name (RNDEP) only when it is executed in the user session but not on the User login script by gpo.

If I run manually the vbs script to add printer into my session on the TS, the printers are mapped without problems.


Spec :
Windows Server 2008 Standard SP1
all MS updates
2 hotfix :
http://support.microsoft.com/kb/955555/en-us
http://support.microsoft.com/kb/949528/en-us

imprimante.vbs script to add my printers :
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
DIM Ordinateur, Imprimante, ImprimanteWin   
Dim fso, MyFile   
Dim Input   
dim arrInput   
dim Debut, fin, AjoutImprimante, Defaut, User, Utilisateur   
Const ForReading = 1   
  
Dim X   
set X = createobject("WSCRIPT.Network")   
dim U   
U=x.UserName   
  
wscript.sleep(2000)   
  
'Création des références d'objets   
Set WshNet = WScript.CreateObject("WScript.Network")   
Set net = WScript.CreateObject("WScript.Network")   
Set WshNetwork = CreateObject("WScript.Network")   
Set WshShell = WScript.CreateObject("WScript.Shell")   
Set WshSysObj = WshShell.Environment("PROCESS")   
  
Set fso = CreateObject("Scripting.FileSystemObject")   
  
 
  
strComputer = "."  
Set objWMIService = GetObject("winmgmts:" _   
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")    
Set colComputer = objWMIService.ExecQuery _   
    ("Select * from Win32_ComputerSystem")   
For Each objComputer in colComputer   
    User= objComputer.UserName   
Next  
  
set net=nothing   
  
  
Imprimante= ""  
ImprimanteWin="aucune"  
  
  
on error resume next   
  
' Identification des imprimantes selon le POSTE de travail    
Set tsInputFile = fso.OpenTextFile("\\UQAT.PRIV\SysVol\UQAT.PRIV\Policies\{2DB4072B-1FA1-4442-8365-B79B386F5DF2}\User\Scripts\Logon\ImprimanteDefinitionNomOrdi.txt", ForReading, False)   
  
  
  
While Not tsInputFile.AtEndOfStream   
  
  strLine = tsInputFile.ReadLine   
  
  if not (strLine ="") and not (left(strLine,1)="'") then    
    arrInput = Split(strLine, ":")   
    Debut = arrInput(0)   
    fin=arrInput(1)   
    AjoutImprimante=arrInput(2)   
    Defaut=arrInput(3)   
    if ((ucase(Ordinateur) >= ucase(Debut) and ucase (ordinateur)<=ucase(fin)) and len(ordinateur)=len(fin)) or ((ucase(Ordinateur) >= ucase(Debut) and ucase (ordinateur)<=ucase(fin)) and len(ordinateur)=len(debut))  then   
     ' A  : ajouter l'imprimante   
     ' D  : définir l'imprimante par défaut   
     ' AD : On ajoute l'imprimante et elle devient l'imprimante par défaut   
       if (ucase(Defaut) = "A") then   
          WshNetwork.AddWindowsPrinterConnection AjoutImprimante   
       end if   
       if (ucase(Defaut) = "D") then   
          WshNetwork.SetDefaultPrinter AjoutImprimante   
       end if   
       if (ucase(Defaut) = "AD") then   
          WshNetwork.AddWindowsPrinterConnection AjoutImprimante   
          WshNetwork.SetDefaultPrinter AjoutImprimante   
       end if   
  
     end if   
  end if   
  
Wend   
  
tsInputFile.Close   
  
WScript.Quit
Open in New Window Select All

Answer : %clientname% environment variable not present at login script on windows server 2008 TS

finally, I have contacted Microsoft. And here is the result :
"I am providing you a copy of our scope agreement for your issue: 2k8 system fail to resolve %clientname% in logon script on terminal server with loopback enabled in replace mode."

to resolve this issue, they asked me to change one setting in the GPO :
Run logon scripts synchronously
Setting Path: User Configuration/Administrative Templates/System/Scripts

It's not a KB article and it will not be one they said.
Random Solutions  
 
programming4us programming4us