天天看點

使用vbs腳本安裝共享列印機

不說廢話,直接上代碼:

<pre class="prism-highlight prism-language-bash">on error resume next
strComputer = "."
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshNETWORK = WScript.CreateObject("WScript.Network")
Set WShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
if InStr(objPrinter.Name,"Canon 2900") then
objPrinter.Delete_
End if
if InStr(objPrinter.Name,"HP 1022") then
objPrinter.Delete_
End if
Next
WShell.Run "cmd /k net use \\192.168.1.17\ipc$ userpassword /USER:username",0
WshNetwork.AddWindowsPrinterConnection "\\192.168.1.17\Samsung K2200 Series"
WShell.Run "cmd /k rundll32 printui.dll,PrintUIEntry /y /n "&chr(34)&"\\192.168.1.17\Samsung K2200 Series"&chr(34)&"",0
WshNetwork.SetDefaultPrinter "\\192.168.1.17\Samsung K2200 Series"
WScript.Echo "安裝完成!"           

複制