【问题标题】:Change default printer based on location根据位置更改默认打印机
【发布时间】:2008-12-20 22:52:45
【问题描述】:

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

【问题讨论】:

    标签: vbscript printers


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      • 2010-11-11
      • 1970-01-01
      • 2011-08-24
      相关资源
      最近更新 更多