none
GPO to add printer?

    Question

  • Hello,

    Can I use a GPO to install a printer via an AD group, but the printer is not on a printer server?  We have a warhouse where there are a few direct TCP/IP printers, but I want to install these on users PC's if they are in a certain AD group?

    Thanks

    Thursday, March 26, 2015 12:23 PM

All replies

  • Yes, you can.

    There is how to do:

    GP preferences: add a new printer

    or you can use logon script.

    Thursday, March 26, 2015 12:33 PM
  • So you can share the printer from someones PC and then use a GPO to map it to others, I guess their PC needs to be on at all times?
    Thursday, March 26, 2015 12:37 PM
  • Yes, or you can use logon script and you dont need running share at comp or server.

    Script like this:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists("C:\Temp\addprinter2.ok") Then
        Wscript.quit
    Else
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    set shell = WScript.CreateObject( "WScript.Shell" )
    CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
        objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
    Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
    Set oShell = WScript.CreateObject("WScript.shell")
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
    
    sub createPort (name, ip)
        objNewPort.Name = name
        objNewPort.Protocol = 1
        objNewPort.HostAddress = ip
        objNewPort.SNMPEnabled = False
        objNewPort.Put_
    end sub
    
    sub addPrinter (driver, port, name)
        objPrinter.DriverName = driver
        objPrinter.PortName = port
        objPrinter.DeviceID = name
        objPrinter.Location = ""
        objPrinter.Network = True
        objPrinter.Shared = false
        objPrinter.ShareName = ""
        objPrinter.Put_
    end sub
    
    createPort "IP_192.168.0.1", "192.168.0.1"
    createPort "IP_192.168.0.2", "192.168.0.2"
    
    
    
    '-------------------------------------------------'    Display name
    'Install printers with externally defined drivers:'    for printer              Driver location                    Port name                  Driver name in .inf file
    '-------------------------------------------------'    -----------       ---------------------------------         ------------               -----------------------  
    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""NRG DSm616 - 1.floor""    /f \\servername.domain.com\scripts$\drv\print\nrg616\OEMSETUP.inf   /r ""IP_192.168.0.1"" /m ""NRG DSm616 PCL 6"""  ,,true
    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""T644 Lexmark - 2.floor""    /f \\servername.domain.com\scripts$\drv\print\LMAAT2DA.inf   /r ""IP_192.168.0.2"" /m ""Lexmark T644"""  ,,true
    
    
    Set objFile = objFSO.CreateTextFile("C:\Temp\addprinter2.ok", True)
    objFile.WriteLine "Script run: " & date & " v " & time
    objFile.Close
    Wscript.sleep 10000
    End if

    Thursday, March 26, 2015 2:59 PM
  • Wow, scripting is not my area at all, so what woud I save this as to run Thennet?

    How would the script look if the printer was on IP address 192.168.100.16 and we wanted it to be called 'Sales-Copier' on everyones computer?

    The printer is actually a copier, but we need to it to use HP Laserjet 4 drivers and be called 'Sales-Copier'

    Is this possible?


    • Edited by TB303 Thursday, March 26, 2015 4:07 PM
    Thursday, March 26, 2015 3:14 PM
  • This script is save and tested, but of course test it on one computer. Better safe then sorry.

    There is modified script:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists("C:\Temp\addprinter.ok") Then
        Wscript.quit
    Else
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    set shell = WScript.CreateObject( "WScript.Shell" )
    CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
        objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
    Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
    Set oShell = WScript.CreateObject("WScript.shell")
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
    
    sub createPort (name, ip)
        objNewPort.Name = name
        objNewPort.Protocol = 1
        objNewPort.HostAddress = ip
        objNewPort.SNMPEnabled = False
        objNewPort.Put_
    end sub
    
    sub addPrinter (driver, port, name)
        objPrinter.DriverName = driver
        objPrinter.PortName = port
        objPrinter.DeviceID = name
        objPrinter.Location = ""
        objPrinter.Network = True
        objPrinter.Shared = false
        objPrinter.ShareName = ""
        objPrinter.Put_
    end sub
    
    createPort "IP_192.168.100.16", "192.168.100.16"
    
    
    '-------------------------------------------------'    Display name
    'Install printers with externally defined drivers:'    for printer              Driver location                    Port name                  Driver name in .inf file
    '-------------------------------------------------'    -----------       ---------------------------------         ------------               -----------------------  
    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""Sales-Copier""    /f \\servername.domain.com\scripts$\drv\print\hp\prnhp001.inf   /r ""IP_192.168.100.16"" /m ""HP LaserJet 4"""  ,,true
    
    
    Set objFile = objFSO.CreateTextFile("C:\Temp\addprinter.ok", True)
    objFile.WriteLine "Script run: " & date & " and " & time
    objFile.Close
    Wscript.sleep 10000
    End if
    1. Script first test if file c:\temp\addprinter.ok exist, if yes then quit, it is for prevent repeated install printer after restart when using same GPO. At the end of script writes file addprinter.ok to c:\temp.
    2. createPort is like adding printer using TCP/IP, just write your printer IP address.
    3. I use Rundll32 printui.dll,printuientry, if you want know more go to Rundll32 printui.dll,PrintUIEntry
    4. Just quick Display name = Sales-Copier, Driver location = \\servername.domain.com\scripts$\drv\print\hp\prnhp001.inf, you must put here correct UNC path to drivers files for printer and if you know something about INF, then you know that driver name in INF file ("HP LaserJet 4") is important for correct driver install, otherwise printer would not be recognized and portname = IP_192.168.100.16 is clear.

    Test it and use it.

    Best Regards

    thennet



    • Edited by thennet Friday, March 27, 2015 7:36 AM
    Friday, March 27, 2015 6:29 AM
  • Hello & thanks,

    Sorrry for the extra questions.

    1. This could be just what I need, so the path  \\servername.domain.com\scripts$\drv\print\hp\prnhp001.inf just needs to be a share location to the printers ini, but our computers have the hp laserjet 4 locally installed, can it not use that?
    2. What do do I save the file as?
    3. Do I just add to the GPO > users > prefs > windows settings > ini
    Friday, March 27, 2015 8:05 AM
  • ad 1) If you know driver path on local disk and path is same for all computers, you can use that.

    ad 2) It is VBScript language (.vbs), save it for example installprint.vbs after do this, you can execute script on test client and test script(correct path driver, name printer, IP, test page, etc.)

    ad 3) Add it to GPO > User Configuration> Policies > Windows Settings > Scripts > Logon, your Users must have privilege to install printers 

    How to do:

    Assign User Logon Scripts

    Create System Startup / Shutdown and User Logon / Logoff Scripts

    Regards

    thennet

    • Edited by thennet Friday, March 27, 2015 10:01 AM
    Friday, March 27, 2015 10:01 AM
  • Thanks, can I run the script manually as a vbs before adding to a GPO?

    I need to work out where the drivers are locatedtoo as these are 64bit pc's.

    Thanks

    Friday, March 27, 2015 10:35 AM
  • Yes, you can save text file as .vbs and run it. You can run script at computers without using GPO.

    You're welcome.

    Friday, March 27, 2015 10:45 AM
  • Hi Thennet,

    Sorry for the delay on this I was on holiday.

    I'm excited to test this script this week!

    One thing, I need to use this on our Citrix 2012 R2 64bit servers, so when someone logs on they get a printer (They use Dell Wyse Thin terminals).

    How can I locate the correct printer driver location (HP laserjet 4 driver), I believe it is local to the server rather than using a UNC?

    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""CAS""    /f \\servername.domain.com\scripts$\drv\print\hp\prnhp001.inf   /r ""IP_192.168.100.16"" /m ""HP LaserJet 4"""  ,,true

    Tuesday, April 07, 2015 10:48 AM
  • Hi,

    by me is easiest way use UNC path, because you can be sure that users always have access to driver path and no one can delete driver files.

    You can use local path, if you have drivers at server in folder, e.g. C:\Drivers\hp\prnhp001.inf, then just change path to:

    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""CAS""    /f C:\Drivers\hp\prnhp001.inf   /r ""IP_192.168.100.16"" /m ""HP LaserJet 4"""  ,,true

    The only condition is, that users who log in to the server must have access to driver path and have read permission.

    Here Rundll32 printui.dll,PrintUIEntry is description of parameters and examples.

    ____________________________________________________

    For example:

    To add a printer using the Add Printer wizard and using an .inf file, InfFile.inf, located on drive c: at InfPath, type:

    rundll32 printui.dll PrintUIEntry /ii /f c:\InfPath\InfFile.inf

    ____________________________________________________

    Regards,

    thennet


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!


    • Edited by thennet Tuesday, April 07, 2015 12:28 PM
    Tuesday, April 07, 2015 12:27 PM
  • Hello,

    I will use the UNC.

    We have to use the HP Laserjet 4 driver (horrid) and the one off HPs site doesn't work well for us, but if I go into the a Windows 8 64bit or Windows 2012 64 bit server and install a printer and choose:

    "The printer that I wand isn't isn't listed" > in the driver location choose Windows Update > and wait a few minutes I can then choose the HP Laserjet 4 driver and this always works.

    I just need a way to extract this drive and put on a network path, is this possible?

    Tuesday, April 07, 2015 12:35 PM
  • You can extract this driver, or you can download it from Microsoft Update Catalog:

    http://catalog.update.microsoft.com/v7/site/Search.aspx?q=microsoft%20driver%20update%20for%20hp%20laserjet%204


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Tuesday, April 07, 2015 1:01 PM
  • Let me take a look, 

    I did find this location C:\Windows\System32\spool\drivers\x64\3

    but I can only see a fiel called HPLJ4.BUD and HPLJ4.GPD are these any good?

    Tuesday, April 07, 2015 1:04 PM
  • Download the Cabinet file Thinnet from that location, lot's of files within it, any idea on where I go from here?  No inf file though.
    Tuesday, April 07, 2015 1:16 PM
  • Here is how to find drivers installed for printer:

    http://www.solveyourtech.com/how-to-see-all-of-the-printer-drivers-currently-installed-in-windows-7/

    For install printer you need inf file and some other files, HPLJ4.GPD is this file. you can find files thats needed in inf file.


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Tuesday, April 07, 2015 1:30 PM
  • If you download CAB file for architecture x64 ( Amd64) and unzip files, there is prnhp001.inf and folder amd64 which contain many files for many printers. Using prnhp001.inf locate needed files for HP LaserJet 4.

    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Tuesday, April 07, 2015 1:42 PM
  • Thanks got the files Thinnet!

    I have tis script below now, can I run manually to outside a GPO first on a user PC to test, if so how?

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists("C:\Temp\addprinter.ok") Then
        Wscript.quit
    Else
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    set shell = WScript.CreateObject( "WScript.Shell" )
    CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
        objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
    Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
    Set oShell = WScript.CreateObject("WScript.shell")
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
     
    sub createPort (name, ip)
        objNewPort.Name = name
        objNewPort.Protocol = 1
        objNewPort.HostAddress = ip
        objNewPort.SNMPEnabled = False
        objNewPort.Put_
    end sub
     
    sub addPrinter (driver, port, name)
        objPrinter.DriverName = driver
        objPrinter.PortName = port
        objPrinter.DeviceID = name
        objPrinter.Location = ""
        objPrinter.Network = True
        objPrinter.Shared = false
        objPrinter.ShareName = ""
        objPrinter.Put_
    end sub
     
    createPort "IP_192.168.100.16", "192.168.100.16"
     
     
    '-------------------------------------------------'    Display name
    'Install printers with externally defined drivers:'    for printer              Driver location                    Port name            
          Driver name in .inf file
    '-------------------------------------------------'    -----------       ---------------------------------         ------------               -----------------------  
    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""CAS""    /f \\svr-files\files\IT\resources\Printer_Drivers\HPLJ4\prnhp001.inf   /r ""IP_192.168.100.16"" /m ""HP LaserJet 4"""
      ,,true
     
     
    Set objFile = objFSO.CreateTextFile("C:\Temp\addprinter.ok", True)
    objFile.WriteLine "Script run: " & date & " and " & time
    objFile.Close
    Wscript.sleep 10000
    End if


    • Edited by TB303 Tuesday, April 07, 2015 1:53 PM
    Tuesday, April 07, 2015 1:52 PM
  • I did try and saves as a .vbs and ran on my PC and got the error:

    Line 3

    Char 1

    Error invalid Character

    code 800A0408

    Source Microsoft VBscript compilation error

    Tuesday, April 07, 2015 1:57 PM
  • First try core of script, whitout testing or creating a file, after then you can try whole script.

    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    set shell = WScript.CreateObject( "WScript.Shell" )
    CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
        objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
    Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
    Set oShell = WScript.CreateObject("WScript.shell")
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
     
    sub createPort (name, ip)
        objNewPort.Name = name
        objNewPort.Protocol = 1
        objNewPort.HostAddress = ip
        objNewPort.SNMPEnabled = False
        objNewPort.Put_
    end sub
     
    sub addPrinter (driver, port, name)
        objPrinter.DriverName = driver
        objPrinter.PortName = port
        objPrinter.DeviceID = name
        objPrinter.Location = ""
        objPrinter.Network = True
        objPrinter.Shared = false
        objPrinter.ShareName = ""
        objPrinter.Put_
    end sub
     
    createPort "IP_192.168.100.16", "192.168.100.16"
     
     
    '-------------------------------------------------'    Display name
    'Install printers with externally defined drivers:'    for printer              Driver location                    Port name            Driver name in .inf file
    '-------------------------------------------------'    -----------       ---------------------------------         ------------               -----------------------  
    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""CAS""    /f \\svr-files\files\IT\resources\Printer_Drivers\HPLJ4\prnhp001.inf   /r ""IP_192.168.100.16"" /m ""HP LaserJet 4""",,true
     


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!


    • Edited by thennet Tuesday, April 07, 2015 2:11 PM
    Tuesday, April 07, 2015 2:10 PM
  • Running the above foudn an error:

    line 36

    char 3

    seems to be "  ,,true"

    Tuesday, April 07, 2015 2:15 PM
  • Posible problem

    Error invalid Character

    code 800A0408

    , solution is here:

    http://stackoverflow.com/questions/2039104/vbscript-invalid-character-800a0408-compilation-error


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Tuesday, April 07, 2015 2:17 PM
  • you have  ,,true on second line, it must be at one line with 

    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /

    like here:

    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""CAS""    /f \\svr-files\files\IT\resources\Printer_Drivers\HPLJ4\prnhp001.inf   /r ""IP_192.168.100.16"" /m ""HP LaserJet 4""",,true
     


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!


    • Edited by thennet Tuesday, April 07, 2015 2:22 PM
    Tuesday, April 07, 2015 2:20 PM
  • Closer, but I got this error

    , if I install manualy and point to \\svr-files\files\IT\resources\Printer_Drivers\HPLJ4\prnhp001.inf I get further but still an error, so close!

    Order 1

    next error on next post


    • Edited by TB303 Tuesday, April 07, 2015 2:36 PM
    Tuesday, April 07, 2015 2:34 PM
  • then 

    order 2

    Order 3




    • Edited by TB303 Tuesday, April 07, 2015 2:37 PM
    Tuesday, April 07, 2015 2:35 PM
  • I can browse to the prnhp001.inf file with no issues and open and browse to the printer:

    ;
    ; Windows Inbox Printer Drivers
    ;
    [Version]
    Signature="$Windows NT$"
    Provider="Microsoft"
    ClassGUID={4D36E979-E325-11CE-BFC1-08002BE10318}
    Class=Printer
    CatalogFile=prnhp001.cat
    DriverVer=06/21/2006,6.1.7233.0


    [Manufacturer]
    "HP"=HP,NTamd64

    [HP.NTamd64]
    "HP LaserJet 4"                    = HPLJ4.GPD,Hewlett-PackardHP_La185F,HP_LaserJet_4 ; Hardware ID

    • Edited by TB303 Tuesday, April 07, 2015 2:48 PM
    Tuesday, April 07, 2015 2:46 PM
  • When you install printer manualy, you have removed some files from Amd64 folder?

    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Tuesday, April 07, 2015 3:09 PM
  • Check permission to driver files, e.g. HPLJ4.GPD, can you access it?

    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Tuesday, April 07, 2015 3:13 PM
  • It look like installer have access to prnhp001.inf, but can't access driver files in Amd64.

    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Tuesday, April 07, 2015 3:18 PM
  • I will check. All I have done is downloaded that cab file, opened it up and copied the files to a folder where this server has access too.
    Tuesday, April 07, 2015 3:57 PM
  • For testing driver files try install printer on test PC from local folder with drivers. If you installed it without error, then is problem with permissions at shared folder on server.

    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Tuesday, April 07, 2015 4:17 PM
  • I have better news, those drivers worked on my Windows 7 64bit PC, but not via the 2012 server, so I manually installed the drivers on the server and copied the HP4 drivers it install via the windows update into the folder I point to and the print installs via the shorterned script :)

    Howerver the full scripts doesn't

    When I try to run the basic shorter script from a Citrix session manually I get this:


    • Edited by TB303 Wednesday, April 08, 2015 9:20 AM
    Wednesday, April 08, 2015 9:08 AM

    For first error with full script try this:

    1. Open the .vbs in notepad
    2. Go to file and "save as"
    3. Right under the file name box, you will see a drop down menu for encoding. Choose ANSI.

    For second error on Citrix session:

    • Instead these lines:

      Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
          objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True

    • Paste these lines and try it:

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


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!



    • Edited by thennet Wednesday, April 08, 2015 10:54 AM
    Wednesday, April 08, 2015 10:42 AM
  • Yeah that worked, I guess I need the rest of the script to work now.  Very clever.

    The big issue I have noticed is the printer needs to be installed in a user context mode, it seems to install the printer in the users session, but I have noticed the printer also gets installed on the actual Citrix server.

    I'm not sure if you have used Citirx before, but it is clever and pulls though your local desktop printers into your Citrix session, these can be locally attached or network printers.

    Wednesday, April 08, 2015 12:54 PM
  • The big issue I have noticed is the printer needs to be installed in a user context mode, it seems to install the printer in the users session, but I have noticed the printer also gets installed on the actual Citrix server.

    I'm not sure if you have used Citirx before, but it is clever and pulls though your local desktop printers into your Citrix session, these can be locally attached or network printers.

    No, I have never used Citrix, but it is similiar functionality like at Remote Desktop at Windows.

    Your first question was:

    Hello,

    Can I use a GPO to install a printer via an AD group, but the printer is not on a printer server?  We have a warhouse where there are a few direct TCP/IP printers, but I want to install these on users PC's if they are in a certain AD group?

    Answer is, if you have printer, which is not installed and shared on some computer and you want install this printer on more than one PC in domain, you can use this script. 

    Now just run full script, for prevent repeating install printer.

    I think it was a good workout for you in scripting :-)

    Best Regards,

    thennet


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Wednesday, April 08, 2015 1:35 PM
  • No you are right, I have widened the original requests as I didn't want to over complicate things.

    I did just delete the printer and logged back in and got this, but I will continue to test

    Wednesday, April 08, 2015 1:39 PM
  • Also what should the full script look like as I know it has been changed somewhat?
    Wednesday, April 08, 2015 1:41 PM
  • Don't think it liked the second line:

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

    Wednesday, April 08, 2015 2:44 PM
  • Don't think it liked the second line:

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

    OK, we can change this two lines to:

    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (LoadDriver)}")

    Also what should the full script look like as I know it has been changed somewhat?

    To get full script, you need to top a script add these bold lines:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists("C:\Temp\addprinter.ok") Then
        Wscript.quit
    Else

    Set WSHNetwork = WScript.CreateObject("WScript.Network")

    and to end a script add these bold lines:

    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry ........

    Set objFile = objFSO.CreateTextFile("C:\Temp\addprinter.ok", True)

    objFile.WriteLine "Script run: " & date & " and " & time

    objFile.Close
    Wscript.sleep 10000
    End if



    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Thursday, April 09, 2015 6:09 AM
  • Hello,

    I've removed the 2 lines and added

    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (LoadDriver)}")

    I'm afraid I get the error:

    The script looks like this

    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    set shell = WScript.CreateObject( "WScript.Shell" )
    CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (LoadDriver)}")
    Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
    Set oShell = WScript.CreateObject("WScript.shell")
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
     
    sub createPort (name, ip)
        objNewPort.Name = name
        objNewPort.Protocol = 1
        objNewPort.HostAddress = ip
        objNewPort.SNMPEnabled = False
        objNewPort.Put_
    end sub
     
    sub addPrinter (driver, port, name)
        objPrinter.DriverName = driver
        objPrinter.PortName = port
        objPrinter.DeviceID = name
        objPrinter.Location = ""
        objPrinter.Network = True
        objPrinter.Shared = false
        objPrinter.ShareName = ""
        objPrinter.Put_
    end sub
     
    createPort "IP_192.168.100.16", "192.168.100.16"
     
     
    '-------------------------------------------------'    Display name
    'Install printers with externally defined drivers:'    for printer              Driver location                    Port name            Driver name in .inf file
    '-------------------------------------------------'    -----------       ---------------------------------         ------------               -----------------------  
    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""CAS""    /f \\svr-fileserver\files\IT\resources\Printer_Drivers\HP\HPLJ4\prnhp001.inf   /r ""IP_192.168.100.16"" /m ""HP LaserJet 4""",,true

    Thursday, April 09, 2015 1:39 PM
  • We must back to the previous code:

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

    Test it.


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Friday, April 10, 2015 6:16 AM
  • Now says:

    error

    Line 4

    Char 42

    Error expected ")"

    So I added this

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

    and now get

    error

    Line 5

    Char 4

    Error invalid car

    Friday, April 10, 2015 7:14 AM
  • This is wrong, you added a parenthesis at the end of first line.


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

    Friday, April 10, 2015 8:08 AM
  • yes, but the error suggested it needs it there?
    Friday, April 10, 2015 8:24 AM
  • Because underscore must be at end of first line, this happend because of text alignment in this forum :-(

    Correct is:

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


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!


    • Edited by thennet Friday, April 10, 2015 9:04 AM
    Friday, April 10, 2015 9:03 AM
  • > *Set objWMIService = GetObject("winmgmts:" _ **&
    > "{impersonationLevel=impersonate, (LoadDriver)}!\\" & CompName &
    > "\root\cimv2")*
     
    Scripting games? :))
     
    The underscore "_" needs to be at the end of the first line, not at the
    beginning of the second one.
     

    Greetings/Grüße, Martin

    Mal ein gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me - coke bottle design refreshment (-:
    Friday, April 10, 2015 10:08 AM
  • Thanks, 

    Now I get 

    Line 15

    Char 5

    Access denied.


    Friday, April 10, 2015 10:19 AM
  • Doesn't help when you have someone like me who is not very clever with scripts :)

    I'm a Cisco engineer....don't ask.

    Friday, April 10, 2015 10:23 AM
  • > I'm a Cisco engineer....don't ask.
     
    THat's fine - all due respect to your will to find a solution!
     

    Greetings/Grüße, Martin

    Mal ein gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me - coke bottle design refreshment (-:
    Friday, April 10, 2015 10:48 AM
  • It's a little bit hard, but life is hard :) 

    We can try it one more time.

    I reduced and edited the script, here is full version with comentary, which marks begin and end of script core:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    set tshell = WScript.CreateObject( "WScript.Shell" )
    Ttemp = tshell.ExpandEnvironmentStrings("%TEMP%")
    If objFSO.FileExists( Ttemp & "\addprinter.ok") Then
        Wscript.quit
    Else
    '---Core of script - start
    set shell = WScript.CreateObject( "WScript.Shell" )
    CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    Set objWMIService = GetObject("winmgmts:" _
      &"{impersonationLevel=impersonate,(LoadDriver)}!\\" & CompName & "\root\cimv2")   
    Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
    Set oShell = WScript.CreateObject("WScript.shell")
    
    sub createPort (name, ip)
        objNewPort.Name = name
        objNewPort.Protocol = 1
        objNewPort.HostAddress = ip
        objNewPort.SNMPEnabled = False
        objNewPort.Put_
    end sub
    
    createPort "IP_192.168.100.16", "192.168.100.16"  
     
    '-------------------------------------------------'    Display name
    'Install printers with externally defined drivers:'    for printer              Driver location                    Port name            Driver name in .inf file
    '-------------------------------------------------'    -----------       ---------------------------------         ------------               -----------------------  
    oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""CAS""    /f \\svr-fileserver\files\IT\resources\Printer_Drivers\HP\HPLJ4\prnhp001.inf   /r ""IP_192.168.100.16"" /m ""HP LaserJet 4""",,true
    '---Core of script - end
    
    Set objFile = objFSO.CreateTextFile( Ttemp & "\addprinter.ok", True)
    objFile.WriteLine "Script run: " & date & " and " & time          
    objFile.Close
    Wscript.sleep 10000
    End if

    If the script does not work, then it will be easier to install a shared printer.

    Here is some ways, how to use GPO for install shared printer:

    Deploying Printers with Group Policy Preferences

    Configure a TCP/IP Printer Item

    Configure a Shared Printer Item

    Test core of this script, I hope it will work.

    Best Regards,

    thennet


    Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!



    • Edited by thennet Sunday, April 12, 2015 4:55 PM
    Sunday, April 12, 2015 4:52 PM