none
How do you get all the printer information using VBA and WMI - Help RRS feed

  • General discussion

  • I have created a printer script, but I want to add the printer setting to the script, Using Multi Feeder etc. But I need to get an export from one Network printer from WMI

    The script

    On Error Resume next
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile _
    ("H:\printers.txt", ForReading)
     Do Until objTextFile.AtEndOfStream
        strNextLine = objTextFile.Readline
        Printconfig = Split(strNextLine , ",")
       Wscript.Echo "Store name: " & Printconfig(0)
        For i = 1 to Ubound(Printconfig)
        Wscript.Echo "Store IP4 Address " & Printconfig(i)
      
    strComputer = "Servername"   
    strDriverName = "Lexmark Universal PS3" 'This needs to match exactly with what is in the INF    
    strDriverFilePath = "\\Servername\C$\windows\system32\spool\drivers\x64\3" 'do I need to explain this?    
    strDriverINF = strDriverFilePath & "NTPRINT.INF" 
    strPortName = "IP_" + Printconfig(1)'this is just an example.  you can name it what you want    
    strPortAddress = PrintConfig(1) 'this is just an example, use ip address or dns name    
    strPrinterName = PrintConfig(0)'name it whatever you want 
    strShare=PrintConfig(0)
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 'Connect to WMI COM object on the target.
           
    'Install the printer driver    
    objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True   
    Set objDriver = objWMIService.Get("Win32_PrinterDriver")    
    objDriver.Name = strDriverName     
    objDriver.SupportedPlatform = "Windows NT x86"   
    objDriver.Version = "3"   
    objDriver.FilePath= strDriverFilePath    
    objDriver.Infname = strDriverINF    
    objDriver.AddPrinterDriver(objDriver)    
       
    'Create a new Standard TCP/IP port with HP Jet Direct Settings    
    Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
    objNewPort.Name = strPortName    
    objNewPort.Protocol = 1    
    objNewPort.HostAddress = strPortAddress   
    objNewPort.PortNumber = "9100"   
    objNewPort.SNMPEnabled = False   
    objNewPort.Put_
                    
    'Create a new printer using the newly installed printer driver and port    
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
    objPrinter.DriverName = strDriverName     
    objPrinter.PortName = strPortName    
    objPrinter.DeviceID = strPrinterName    
    objPrinter.Location = ""   
    objPrinter.Network = True   
    objPrinter.Shared = True  
    objPrinter.Docompletefirst = True
    objPrinter.ShareName = strShare 
    objPrinter.Put_
      
      Next
    Loop

    • Changed type Bill_Stewart Monday, October 2, 2017 10:02 PM
    • Moved by Bill_Stewart Monday, October 2, 2017 10:03 PM Already asked and answered
    Wednesday, August 30, 2017 2:32 PM

All replies