需要在登录时根据主机名调用脚本。Win 2k3 域和 XP/7 工作站

需要在登录时根据主机名调用脚本。Win 2k3 域和 XP/7 工作站

我有一个用户登录脚本。我想根据主机名安装打印机。此文件夹内有 \domain.local\SYSVOL\domain.local\Policies{DF3F608C-8D78-934F-B79F-1965F3C4409B}\User\Scripts\Logon

我有每个主机/工作站的 cmd 文件和 logon.cmd。

终端服务器遵守环境变量 %clientname%,但工作站却不遵守。

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

摘自 clientname.cmdL:

rundll32 printui,PrintUIEntry /in /n\\fileserv\PhaserPS
rundll32 printui,PrintUIEntry /in  /n\\fileserv\CanonIR
rundll32 printui,PrintUIEntry /y  /n\\fileserv\CanonIR

答案1

%CLIENTNAME%除非您通过 RDP 连接到计算机,否则该变量不存在。您可能应该拨打电话%COMPUTERNAME%

您可以为使用 的终端服务器指定不同的脚本%CLIENTNAME%。或者,您可以在脚本中编写一个条件,%CLIENTNAME%如果存在则使用 ,如果不存在则尝试%COMPUTERNAME%

答案2

Zoredache 说得对。另外,如果你想检查一个变量是否为空,你可以执行以下操作:

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

如果省略引号,批处理解释将只会看到“if not == echo all your...”并抛出错误。

相关内容