Add printer driver (VBScript)

This code can be found in Chapter 9 of Active Directory Cookbook, 2nd edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' The following script will add a printer driver, and then
' list all the installed drivers on a particular computer
'----------------- SCRIPT CONFIGURATION ----------------------
strComputer = "<ComputerName>" ' use "." for the local computer
strDriverName = "<DriverName>" ' i.e. "HP Laserjet 4050 TN"
strPlatform = "<PlatformName>" ' i.e. "Windows NT X66"
strVersion = "<VersionNumber>" ' i.e. "3" for XP/2000
'----------------- END CONFIGURATION -------------------------

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objDriver = objWMIService.Get("Win32_PrinterDriver")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True

objDriver.Name = strDriverName
objDriver.SupportedPlatform = strPlatform
objDriver.Version = strVersion
errResult = objDriver.AddPrinterDriver(objDriver)

' Now list all installed printer drivers
Set installedPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_PrinterDriver")

For each printer in installedPrinters
    Wscript.Echo "Name: " & printer.Name
    Wscript.Echo "Description: " & printer.Description
    Wscript.Echo "Driver Path: " & printer.DriverPath
    Wscript.Echo "File Path: " & printer.FilePath
    Wscript.Echo "Version: " & printer.Version
Next

This code has been viewed 9982 times.

New from the creators of TechTasks.com: StatSheet.com