我正在尝试编辑机器默认打印机首选项。更具体地讲,我想每个打印类型更改为锁定打印,然后分配给各个用户的用户名和密码:使用VBScript编辑默认打印机首选项作业类型
每个人都在PCL6打印机驱动程序,但我不知道如何从VBScript中访问这个。这是我到目前为止。我一直在尽可能多地注释它,所以希望如果我离开的话能够理解它的人。全部在工作状态:
Option Explicit
' Tell WSH to resume on errors, otherwise our error handling can't do it's job
On Error Resume Next
' Define variables
Dim objNetwork, objWMIService, objPrinter
Dim colInstalledPrinters
Dim strPrinterServer, strPrinterShare, strUserName, strPassword, strPrinterName
Dim Return, LocalDefault
Dim DynamicMessage
Dim DefaultPrinter
strPrinterServer = "\\GBDSCWSSC0125"
strPrinterShare = "GBGBMIL1NPSC000"
strPassword = "1234"
msgbox("This tool will set up your default printer with a username and password. When changing default printers, please run this tool again")
strUserName = CreateObject("WScript.Network").UserName
DynamicMessage = msgbox("Your username is " & strUserName & vbNewLine & "Is this correct?", vbYesNo)
If DynamicMessage = vbNo Then
strUserName = InputBox("Please enter your username")
DynamicMessage = msgbox("Your username is " & strUserName, vbOK)
End If
' Get WMIService so we can run WMI queries (windows management instrumentation). Basically a library for controlling windows
Set objWMIService = GetObject(_
"winmgmts:" & "{impersonationLevel=impersonate}!\\" _
& strComputerName & "\root\cimv2")
' Run a WMI query to get all the installed printers. This returns a collection so the variable uses the "col" prefix
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
' The WMI query returns a collection that we need to loop through and check to see if the current printer object is the default printer
For Each objPrinter in colInstalledPrinters
If objPrinter.Default = "True" Then
If objPrinter.Name <> "Microsoft Office Document Image Writer" Then
LocalDefault = True
strPrinterName = objPrinter.Name
DynamicMessage = msgbox("Default printer is " & strPrinterName, vbOKOnly)
End If
End If
Next
msgbox("Done!")
Set objWMIService = Nothing
Set objNetwork = Nothing
WScipt.Quit
这是不是可能?
你在用什么打印机?也许是RICOH? – JoSerra
是的,我们在办公室附近有各种RICOH打印机,但它们都使用相同的驱动程序。 – JaayB
Hi @JaayB Ricoh打印机队列在PRINT SERVER上包含一个XML文件,它在这个注册表项上存储了一些打印机首选项** HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Print \ Printers \ \ PrinterDriverData \ capsdb_scope :: UI_Customize ** 。 您可以使用[打印机驱动程序包装器NX软件](http://support.ricoh.com/html_gen/util/PDP/PDP.html)创建自定义配置文件 我认为您可以将打印作业的用户标识设置为当前的Windows登录名,但我不知道如何设置密码字段。 –
JoSerra