Edit Default Printer Preferences Job Type with VBScript

2.2k views Asked by At

I am trying to edit a machines default printer preferences. More specifically, I am trying to change each print type into a locked print, and then assign a username and password to each individual user:

settings to be edited

Everyone is on the PCL6 printer drivers but I have no idea how to access this from within VBScript. Here is what I have so far. I have been annotating it as much as I can so hopefully whoever picks this up if I leave will be able to understand it. All is in working order:

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

Is this at all possible?

1

There are 1 answers

4
JoSerra On

You can try setting registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\printername\PrinterDriver‌​Data\capsdb_scope::U‌​I_Customize on print server with this value:

<?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>