add one printer ===================
Set WshNetwork10 = CreateObject("WScript.Network")
WshNetwork10.AddWindowsPrinterConnection \\PrinterServer\PRN-Color
Delete All Print==============
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
但如果要在User 端直接連到printer(不透過printer server),安裝時需要管理者權限,如果要請user自行安裝因為權限不足,無法安裝,所以腦筋動行RUNAS,雖然可以處理,但管理者密碼會有洩露之虞,此可參考網友文章
- 解決執行RUNAS,自動帶密碼的方法
- runas 自動輸入密碼 VBS 用screnc加密不支援vista以上版本
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:domain\administrator ""c:\test\h.bat"""
WScript.Sleep 1000
WshShell.Sendkeys "password~"
WScript.Sleep 5000使用AutoIt也是一個不錯的選擇 http://www.autoitscript.com/site/
注意administrator後面紅色部份是一個space