为特定用户设置默认打印机的脚本

为特定用户设置默认打印机的脚本

我们的实验室安装了多台打印机。我们在 AD 中有一个特殊的测试帐户,该帐户无法打印到进行测试的房间,以保护个人信息。

我需要一个登录脚本,根据该用户是否登录将不同的打印机设置为默认打印机。

这就是我们现在按 OU 设置默认打印机的方法。我想在末尾为用户添加一行。

Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.ComputerName

arrComputerName = Split(strName, ",")
arrOU = Split(arrComputerName(1), "=")
strComputerOU = arrOU(1) 

Set objNetwork = CreateObject("WScript.Network")

Select Case strComputerOU
Case "OU for Printer 1"

    objNetwork.SetDefaultPrinter "Printer 1"

Case "OU for Printer 2"

    objNetwork.SetDefaultPrinter "Printer 2"

Case "OU for Printer 3"

    objNetwork.SetDefaultPrinter "Printer 3"

Case "LabColorPrinter"

    objNetwork.SetDefaultPrinter "Color Printer"

Case Else
    objNetwork.SetDefaultPrinter "Printer 1"

End Select

答案1

尽管测试帐户仍然可以更改打印机,但以下内容应该可以满足您的要求。

Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.ComputerName

arrComputerName = Split(strName, ",")
arrOU = Split(arrComputerName(1), "=")
strComputerOU = arrOU(1) 

Set objNetwork = CreateObject("WScript.Network")

If objNetwork.UserName = "TestUsername" Then
    objNetwork.SetDefaultPrinter "Printer X"
Else

    Select Case strComputerOU
        Case "OU for Printer 1"
            objNetwork.SetDefaultPrinter "Printer 1"

        Case "OU for Printer 2"
            objNetwork.SetDefaultPrinter "Printer 2"

        Case "OU for Printer 3"
            objNetwork.SetDefaultPrinter "Printer 3"

        Case "LabColorPrinter"
            objNetwork.SetDefaultPrinter "Color Printer"

        Case Else
            objNetwork.SetDefaultPrinter "Printer 1"
    End Select

End If

相关内容