Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

VBScript to install a network printer that uses a local driver

$
0
0

Hey guys,

I have been working on a script to install a network printer that uses a printer driver located on the C:\ drive of the user's computer (Sorry if my wording is confusing). I have the UNC path of the printer, but every time I run the script it fails to install becasue of an unknown driver. Basically, the printer is on an '03 32-bit print server and I am trying to install the printer on a x64 machine. My attempted work around is to install the driver then install the network printer. But, this attempt isn't working and I'm hoping you can help. Below is the call to the driver function, the driver function I am calling, and an excerpt that shows how I install the printer after the driver call:

Call Driver("Lexmark Universal v2 PS3", "C:\PrinterInstall\Drivers\UniversalDriver\Admin\Drivers\Print\GDI\LMUD1O40.inf")

'************************************************************************ 'Driver Install Function '************************************************************************ Function Driver(name, inf) 'name, 'platform, version, path, inf Dim result, objDriver, objInfname WScript.Echo "Name is: " & name & " and INF is: " & inf Set objDriver = objWMIService.Get("Win32_PrinterDriver") objDriver.Name = name 'objDriver.SupportedPlatform = "$Windows NT$" 'platform 'objDriver.Version = version 'objDriverPath = path objInfname = inf result = objDriver.AddPrinterDriver(objDriver) 'Add the driver If result<> 0 Then WScript.Echo "Failed to map printer driver. Error number: " & result End If End Function

'************ Code excerpt to install the printer **************

'Create the Network Object
    Set objNetwork = CreateObject("WScript.Network")  
 
    'Create a new connection to the specified Printer Path
    objNetwork.AddWindowsPrinterConnection strPrinterServer & "\" & strPrinterTag
 
    ' Check to see if an error was logged
    If Err.Number <> 0 Then
       IF Err.Number = -2147023099 Then
    ' Error number is for unknown printer driver
        WScript.Echo "Could not map " & strPrinterServer & "\" _
                 & strPrinterTag & vbcrlf & "Error Number: " & Hex(Err.Number) & ", Printer Driver is unknown."
       Else
        'An error was logged, display error message indicating the error number
        WScript.Echo "Could not map " & strPrinterServer & "\" _
                & strPrinterTag & " Error Number: " & Hex(Err.Number) & ""
       End If
        Err.Clear
         
 End If

My main question is how can I code it so that the Universal Driver I just created in the driver function is used for the network printer?


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>