0
而不是爲每臺計算機編寫我想將使用相同打印機的計算機放入一個組中,並且如果任何計算機名稱是該組的一部分,則它會說打印機。我已經嘗試了許多不同的方式,並且無法將它單獨指定爲一組。它最終添加了所有的打印機。打印機腳本 - 試圖創建組
on error resume next
DIM ComputerName, RegEntry, CPWRIT_A, CPWRIT_B, CPWRNH_A, CPWRNH_B, CPWRNH_C
`'***************_Get Computername_************************************************
RegEntry = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"
ComputerName = ReadRegValue(RegEntry)
'**********************_Computer Groups_******************************************
CPWRIT_A = "CPWRIT00, CPWRIT01, CPWRIT02, CPWRIT03"
CPWRIT_B = "CPWRIT04, CPWRIT05, CPWRIT06"
CPWRNH_A = "CPWRNH01, CPWRNH02, CPWRNH03, CPWRNH04"
CPWRNH_B = "CPWRNH05, CPWRNH06, CPWRNH07, CPWRNH08"
CPWRNH_C = "CPWRNH09, CPWRNH10, CPWRNH11, CPWRNH12, CPWRNH13"
'*****************_WR Nurse Hall_*********************************************************
IF ComputerName(CPWRNH_A) THEN
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\hpdl120\Nurse1_WhitePaper"
objNetwork.AddWindowsPrinterConnection "\\hpdl120\Nurse1_RX_Paper"
objNetwork.AddWindowsPrinterConnection "\\cpwrnh03\DYMO_CPWRNH03"
objNetwork.AddWindowsPrinterConnection "\\hpdl120\SAVIN_WRN"
objNetwork.SetDefaultPrinter "\\hpdl120\Nurse1_WhitePaper"
ELSE
END IF
IF ComputerName(CPWRNH_B) THEN
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\hpdl120\SAVIN_WRN"
objNetwork.AddWindowsPrinterConnection "\\cpwrnh07\DYMO_CPWRNH07"
objNetwork.SetDefaultPrinter "\\hpdl120\SAVIN_WRN"
ELSE
END IF
IF ComputerName(CPWRNH_C) THEN
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\hpdl120\Nurse2_Tray1_RX"
objNetwork.AddWindowsPrinterConnection "\\hpdl120\Nurse2_Tray2_PlainPaper"
objNetwork.AddWindowsPrinterConnection "\\hpdl120\SAVIN_WRN"
objNetwork.AddWindowsPrinterConnection "\\hpdl120\cdnurse_Dymo"
objNetwork.SetDefaultPrinter "\\hpdl120\Nurse2_Tray2_PlainPaper"
ELSE
END IF
'*****************_WR IT Dept_*********************************************************
IF ComputerName(CPWRIT_A) THEN
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\hpdl120\WR_IT"
objNetwork.AddWindowsPrinterConnection "\\hpdl120\Savin_Admin"
objNetwork.AddWindowsPrinterConnection "\\cpsysop01\SAVIN_AdminTray4"
objNetwork.SetDefaultPrinter "\\hpdl120\WR_IT"
ELSE
END IF
IF ComputerName(CPWRIT_B) THEN
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\hpdl120\WR_IT"
objNetwork.AddWindowsPrinterConnection "\\hpdl120\Savin_Admin"
objNetwork.AddWindowsPrinterConnection "\\cpsysop01\SAVIN_AdminTray4"
objNetwork.SetDefaultPrinter "\\hpdl120\Savin_Admin"
ELSE
END IF
'*******************************************************************************
wscript.quit
'*****************_Returns the data in the registry value_**********************
FUNCTION ReadRegValue(ByVal RegValue)
DIM WSHShell
SET WSHShell = WScript.CREATEOBJECT("WScript.Shell")
ReadRegValue = ""
ON ERROR RESUME NEXT
ReadRegValue = WSHShell.RegRead(RegValue)
END FUNCTION
您應該使用Windows網絡安全策略和專門的管理工具,據我所知您在域控網絡。不要試圖製作自制腳本,因爲這樣只會損害您的網絡安全。 –