1

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?

JaayB
  • 138
  • 2
  • 14
  • What printer are you using ? Perhaps a RICOH ? – JoSerra Aug 31 '17 at 05:19
  • Yep, we have various RICOH printers around the office but they all run off the same drivers. – JaayB Aug 31 '17 at 09:25
  • Hi @JaayB Ricoh printer queue stores some printer preferences on this registry key **HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\\PrinterDriverData\capsdb_scope::UI_Customize** on PRINT SERVER which contains an XML file. You can create a customized configuration file with [Printer Driver Packager NX software](http://support.ricoh.com/html_gen/util/PDP/PDP.html) I think you can set printjob's User id to current windows loginname, but i don´t known how to set Password field. – JoSerra Aug 31 '17 at 16:20

1 Answers1

0

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>
JoSerra
  • 361
  • 2
  • 9
  • I can get as far as HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\HP Universl Printing PCL 6\PrinterDriverData but past that I cant find a capsdb_scope::UI... within the registry. Forgive me if I sound a bit oblivious to all this. I've edited the registry before but always done it blindly because I've been told to. I may have to take some time to read up and understand it. – JaayB Sep 01 '17 at 12:20
  • You must check that registry entry in your print server (GBDSCWSSC0125). What is your printer driver name ? – JoSerra Sep 01 '17 at 15:11
  • I was a bit cheeky and searched for the username I entered into the printer preferences within the registry and managed to locate the UserID/Username field and password fields. Im just trying to find the one that now changes the type and I should be set.... I think. Still wrapping my head around the XML to change the registry but it should click eventually. Found it in HKEY_CURRENT_USER > SOFTWARE > RICOH > JOBCODE > JCUserID \\\ – JaayB Sep 01 '17 at 15:25
  • I believe I am making progress. I couldn't find the type in the registry, but I may be able to load a .RCF file which has the already set. Then I can assign the username and password afterwards from the registry (since it is not accessible from within this file). Time to get to work! – JaayB Sep 01 '17 at 16:07