1
我正在嘗試使腳本將網絡打印機連接到用戶計算機。 該腳本使用需要打印機作爲參數的計算機名稱。VBS使用LIKE比較字符串「子或功能未定義」
打印機名稱與它們的打印服務器名稱相似,例如。 server_USA有打印機,如printer_USA01,printer_USA02。
但它在第一次到達時拋出錯誤「Sub or Function not defined」...爲什麼?
Set shl = WScript.CreateObject("WScript.Shell")
strName = Wscript.Arguments.Item(0)
'input Printer name
strPrinter = InputBox("Please enter share name of printer to install:", _
"Add network printer")
if strPrinter = "" then
msgbox "Can't be empty."
WScript.quit
elseif strPrinter Like "printer_USA*" then
strServer = server_USA
elseif strPrinter Like "printer_SPAIN*" then
strServer = server_SPAIN
else
'Printer name NOT registered, input printserver manually:
strServer = inputbox("Please enter the name of the printserver","printserver")
if strServer = "" then
msgbox "Can't be empty."
WScript.quit
End if
End if
'ADD
shl.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /ga /c\\" & strName & " /n\\" & strServer & "\" & strPrinter
據我所知,'Like'操作者不會在VBS支持。改用InStr來代替 – MrPaulch