我正在尝试编辑计算机默认的打印机首选项。更具体地说,我试图将每种打印类型更改为锁定的打印,然后为每个用户分配用户名和密码:
每个人都在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
这一切都可能吗?
答案 0 :(得分:0)
您可以尝试使用此值在打印服务器上设置注册表项HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Print \ Printers \ printername \ PrinterDriver Data \ capsdb_scope :: U I_Customize:
<?xml version="1.0" encoding="utf-8"?>
<rcf version="1.0">
<devicesettings drivername="RICOH MP 402SPF PCL 6" independent="yes">
<item name="userid_type" value="windowsloginname"/>
<item name="jobtype" value="lockedprint"/>
</devicesettings>
<featurelock>
<item fixvalue="windowsloginname" name="userid_type"/>
<item fixvalue="lockedprint" name="jobtype"/>
</featurelock>
<popupbeforeprint type="jobtype">
<item defaultstring="default" name="username"/>
<item defaultstring="blank" name="password"/>
<item defaultstring="default" name="userid"/>
</popupbeforeprint>
</rcf>