根据位置更改默认打印机

时间:2008-12-20 22:52:45

标签: vbscript printers

我想根据连接的打印机编写一个VBScript来更改默认打印机   我有一台笔记本电脑,我在工作和家里使用,我想在启动Windows时运行此脚本,因此默认打印机始终是正确的。
  如果在XP中还有另一种方法可以做到这一点,我会全力以赴。

1 个答案:

答案 0 :(得分:2)

WMI可能适合。

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Name = 'ScriptedPrinter'")
For Each objPrinter in colInstalledPrinters
If objPrinter.Name="SomePrinterName" Then 
    objPrinter.SetDefaultPrinter()
End If
Next

- http://msdn.microsoft.com/en-us/library/aa394598(VS.85).aspx

您还可以找到域名等:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings 
    Wscript.Echo "System Name: " & objComputer.Name
    Wscript.Echo "Domain: " & objComputer.Domain
Next

- http://msdn.microsoft.com/en-us/library/aa394586.aspx