I cut and paste the script below from various Microsoft web pages. My
intention is to delete a specific ip printing port (if it exists), add it
under my terms, and then add the actual printer. I think I've found all the
proper code except for adding the printer itself! Can anyone please help me
out?

Thanks,
Jeremy

Code
------------------------------------------------------
'add-ip-printer.vbs
'used to setup a Lexmark Optra S 1650 (PS) printer on ip port 10.24.124.71

'Before this script runs, a batch file with the following command runs
'to delete all local printers
'cscript prnmngr.vbs -x

'Make sure port we want to add is not added under some other name

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

Set colInstalledPorts = objWMIService.ExecQuery ("Select * from
Win32_TCPIPPrinterPort Where Name = 'IP_10.24.124.71'")

For Each objPort in colInstalledPorts
objPort.Delete_
Next

'Delete all unused printer ports

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

Set colPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")

For Each objPrinter in colPrinters
objDictionary.Add objPrinter.PortName, objPrinter.PortName
Next

Set colPorts = objWMIService.ExecQuery ("Select * from
Win32_TCPIPPrinterPort")
For Each objPort in colPorts
If objDictionary.Exists(objPort.Name) Then
Else
ObjPort.Delete_
End If
Next

'Add our printer port

strComputer = "."
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get ("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = "IP_10.24.124.71"
objNewPort.Protocol = 1
objNewPort.HostAddress = "10.24.124.71"
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_

'Add printer driver if not already in list
'Not required for this particular script

'strComputer = "."
'Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege",
True
'Set objDriver = objWMIService.Get("Win32_PrinterDriver")

'objDriver.Name = "NewPrinter Model 2900"
'objDriver.SupportedPlatform = "Windows NT x86"
'objDriver.Version = "3"
'objDriver.DriverPath = "C:\Scripts\NewPrinter.dll"
'objDriver.Infname = "C:\Scripts\NewPrinter.inf"
'intResult = objDriver.AddPrinterDriver(objDriver)

'Add the actual printer
'??????????????

'Make the printer default
strComputer = "."
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from
Win32_Printer Where Name = 'ScriptedPrinter'")

For Each objPrinter in colInstalledPrinters
objPrinter.SetDefaultPrinter()
Next

Re: add an ip printer to workstation by ThatsIT

ThatsIT
Wed Jan 24 07:45:33 CST 2007

http://dev.thatsit.net.au/Samples/WSH/thatsIT/network/default.asp


"Jeremy Schubert" <jschubert@no*spam.shaw.ca> wrote in message
news:OgMiMy0PHHA.1380@TK2MSFTNGP05.phx.gbl...
>I cut and paste the script below from various Microsoft web pages. My
>intention is to delete a specific ip printing port (if it exists), add it
>under my terms, and then add the actual printer. I think I've found all
>the proper code except for adding the printer itself! Can anyone please
>help me out?
>
> Thanks,
> Jeremy
>
> Code
> ------------------------------------------------------
> 'add-ip-printer.vbs
> 'used to setup a Lexmark Optra S 1650 (PS) printer on ip port 10.24.124.71
>
> 'Before this script runs, a batch file with the following command runs
> 'to delete all local printers
> 'cscript prnmngr.vbs -x
>
> 'Make sure port we want to add is not added under some other name
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colInstalledPorts = objWMIService.ExecQuery ("Select * from
> Win32_TCPIPPrinterPort Where Name = 'IP_10.24.124.71'")
>
> For Each objPort in colInstalledPorts
> objPort.Delete_
> Next
>
> 'Delete all unused printer ports
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")
>
> For Each objPrinter in colPrinters
> objDictionary.Add objPrinter.PortName, objPrinter.PortName
> Next
>
> Set colPorts = objWMIService.ExecQuery ("Select * from
> Win32_TCPIPPrinterPort")
> For Each objPort in colPorts
> If objDictionary.Exists(objPort.Name) Then
> Else
> ObjPort.Delete_
> End If
> Next
>
> 'Add our printer port
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set objNewPort = objWMIService.Get
> ("Win32_TCPIPPrinterPort").SpawnInstance_
>
> objNewPort.Name = "IP_10.24.124.71"
> objNewPort.Protocol = 1
> objNewPort.HostAddress = "10.24.124.71"
> objNewPort.PortNumber = "9999"
> objNewPort.SNMPEnabled = False
> objNewPort.Put_
>
> 'Add printer driver if not already in list
> 'Not required for this particular script
>
> 'strComputer = "."
> 'Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> 'objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege",
> True
> 'Set objDriver = objWMIService.Get("Win32_PrinterDriver")
>
> 'objDriver.Name = "NewPrinter Model 2900"
> 'objDriver.SupportedPlatform = "Windows NT x86"
> 'objDriver.Version = "3"
> 'objDriver.DriverPath = "C:\Scripts\NewPrinter.dll"
> 'objDriver.Infname = "C:\Scripts\NewPrinter.inf"
> 'intResult = objDriver.AddPrinterDriver(objDriver)
>
> 'Add the actual printer
> '??????????????
>
> 'Make the printer default
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from
> Win32_Printer Where Name = 'ScriptedPrinter'")
>
> For Each objPrinter in colInstalledPrinters
> objPrinter.SetDefaultPrinter()
> Next
>
>
>



Re: add an ip printer to workstation by Jeremy

Jeremy
Wed Jan 24 08:23:10 CST 2007

Thanks for your reply. But that only shows how to add printers attached to
a server or workstation. I'd like to know how to set up a printer on the
workstation's IP port because there is no server in the building.

"ThatsIT.com.au" <slim@thatsIT> wrote in message
news:OYGLt37PHHA.4492@TK2MSFTNGP02.phx.gbl...
> http://dev.thatsit.net.au/Samples/WSH/thatsIT/network/default.asp
>
>
> "Jeremy Schubert" <jschubert@no*spam.shaw.ca> wrote in message
> news:OgMiMy0PHHA.1380@TK2MSFTNGP05.phx.gbl...
>>I cut and paste the script below from various Microsoft web pages. My
>>intention is to delete a specific ip printing port (if it exists), add it
>>under my terms, and then add the actual printer. I think I've found all
>>the proper code except for adding the printer itself! Can anyone please
>>help me out?
>>
>> Thanks,
>> Jeremy
>>
>> Code
>> ------------------------------------------------------
>> 'add-ip-printer.vbs
>> 'used to setup a Lexmark Optra S 1650 (PS) printer on ip port
>> 10.24.124.71
>>
>> 'Before this script runs, a batch file with the following command runs
>> 'to delete all local printers
>> 'cscript prnmngr.vbs -x
>>
>> 'Make sure port we want to add is not added under some other name
>>
>> strComputer = "."
>> Set objWMIService = GetObject("winmgmts:" &
>> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>>
>> Set colInstalledPorts = objWMIService.ExecQuery ("Select * from
>> Win32_TCPIPPrinterPort Where Name = 'IP_10.24.124.71'")
>>
>> For Each objPort in colInstalledPorts
>> objPort.Delete_
>> Next
>>
>> 'Delete all unused printer ports
>>
>> strComputer = "."
>> Set objWMIService = GetObject("winmgmts:" &
>> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>>
>> Set colPrinters = objWMIService.ExecQuery ("Select * from
>> Win32_Printer")
>>
>> For Each objPrinter in colPrinters
>> objDictionary.Add objPrinter.PortName, objPrinter.PortName
>> Next
>>
>> Set colPorts = objWMIService.ExecQuery ("Select * from
>> Win32_TCPIPPrinterPort")
>> For Each objPort in colPorts
>> If objDictionary.Exists(objPort.Name) Then
>> Else
>> ObjPort.Delete_
>> End If
>> Next
>>
>> 'Add our printer port
>>
>> strComputer = "."
>> Set objWMIService = GetObject("winmgmts:" &
>> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>> Set objNewPort = objWMIService.Get
>> ("Win32_TCPIPPrinterPort").SpawnInstance_
>>
>> objNewPort.Name = "IP_10.24.124.71"
>> objNewPort.Protocol = 1
>> objNewPort.HostAddress = "10.24.124.71"
>> objNewPort.PortNumber = "9999"
>> objNewPort.SNMPEnabled = False
>> objNewPort.Put_
>>
>> 'Add printer driver if not already in list
>> 'Not required for this particular script
>>
>> 'strComputer = "."
>> 'Set objWMIService = GetObject("winmgmts:" &
>> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>> 'objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege",
>> True
>> 'Set objDriver = objWMIService.Get("Win32_PrinterDriver")
>>
>> 'objDriver.Name = "NewPrinter Model 2900"
>> 'objDriver.SupportedPlatform = "Windows NT x86"
>> 'objDriver.Version = "3"
>> 'objDriver.DriverPath = "C:\Scripts\NewPrinter.dll"
>> 'objDriver.Infname = "C:\Scripts\NewPrinter.inf"
>> 'intResult = objDriver.AddPrinterDriver(objDriver)
>>
>> 'Add the actual printer
>> '??????????????
>>
>> 'Make the printer default
>> strComputer = "."
>> Set objWMIService = GetObject("winmgmts:" &
>> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>>
>> Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from
>> Win32_Printer Where Name = 'ScriptedPrinter'")
>>
>> For Each objPrinter in colInstalledPrinters
>> objPrinter.SetDefaultPrinter()
>> Next
>>
>>
>>
>
>



Re: add an ip printer to workstation by E

E
Wed Jan 24 08:32:25 CST 2007

You don't need to have a print server in the building, just at the location
(i.e. same base), it's preferred that it be in the same building/subnet.

Jeremy Schubert wrote:
> Thanks for your reply. But that only shows how to add printers attached to
> a server or workstation. I'd like to know how to set up a printer on the
> workstation's IP port because there is no server in the building.
>

<SNIP>

Re: add an ip printer to workstation by skipjack

skipjack
Wed Jan 24 09:49:09 CST 2007

This is what I had in mine to add the printer:

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

Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

objPrinter.DriverName = drvr_name
objPrinter.PortName = "IP_" & port_ip
objPrinter.DeviceID = Printer_name
objPrinter.Network = True
objPrinter.Shared = False
objPrinter.Put_


My problem was loading drivers... I followed microsoft's example to
load printer drivers via vbscript.. but, it would go throught the
motions but not load the driver. I don't know if the problem was a
security issue or what.. so I wound up loading my drivers via a
rundll32 through a command shell. It works great now. Let me know if
you want me to post the rest.


Re: add an ip printer to workstation by Jeremy

Jeremy
Wed Jan 24 10:09:18 CST 2007

:)))
The location is one building (an elementary school). We're not going to put
a server there for one printer!
"E C H (He of too much code)" <glasswalkertheurge@juno.com> wrote in message
news:OMVc9R8PHHA.4824@TK2MSFTNGP02.phx.gbl...
> You don't need to have a print server in the building, just at the
> location (i.e. same base), it's preferred that it be in the same
> building/subnet.
>
> Jeremy Schubert wrote:
>> Thanks for your reply. But that only shows how to add printers attached
>> to a server or workstation. I'd like to know how to set up a printer on
>> the workstation's IP port because there is no server in the building.
>>
>
> <SNIP>



Re: add an ip printer to workstation by Jeremy

Jeremy
Wed Jan 24 18:12:03 CST 2007

Yes, please post the rest. Thanks.
"skipjack" <david.j.poehlman@cingular.com> wrote in message
news:1169653749.355949.34860@l53g2000cwa.googlegroups.com...
> This is what I had in mine to add the printer:
>
> 'Add printer
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
>
> Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
>
> objPrinter.DriverName = drvr_name
> objPrinter.PortName = "IP_" & port_ip
> objPrinter.DeviceID = Printer_name
> objPrinter.Network = True
> objPrinter.Shared = False
> objPrinter.Put_
>
>
> My problem was loading drivers... I followed microsoft's example to
> load printer drivers via vbscript.. but, it would go throught the
> motions but not load the driver. I don't know if the problem was a
> security issue or what.. so I wound up loading my drivers via a
> rundll32 through a command shell. It works great now. Let me know if
> you want me to post the rest.
>



Re: add an ip printer to workstation by skipjack

skipjack
Sun Jan 28 20:48:48 CST 2007

Sorry about the wait. I'll post it tomorrow AM when I get back to the
office.. I've been out of town.

On Jan 24, 6:12 pm, "Jeremy Schubert" <jschubert@no*spam.shaw.ca>
wrote:
> Yes, please post the rest. Thanks."skipjack" <david.j.poehl...@cingular.com> wrote in messagenews:1169653749.355949.34860@l53g2000cwa.googlegroups.com...
>
>
>
> > This is what I had in mine to add the printer:
>
> > 'Add printer
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer &
> > "\root\cimv2")
>
> > Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
>
> > objPrinter.DriverName = drvr_name
> > objPrinter.PortName = "IP_" & port_ip
> > objPrinter.DeviceID = Printer_name
> > objPrinter.Network = True
> > objPrinter.Shared = False
> > objPrinter.Put_
>
> > My problem was loading drivers... I followed microsoft's example to
> > load printer drivers via vbscript.. but, it would go throught the
> > motions but not load the driver. I don't know if the problem was a
> > security issue or what.. so I wound up loading my drivers via a
> > rundll32 through a command shell. It works great now. Let me know if
> > you want me to post the rest.- Hide quoted text -- Show quoted text -


Re: add an ip printer to workstation by skipjack

skipjack
Mon Jan 29 09:05:52 CST 2007

Here's my script. I support about 20 sites, each with their own IP
printing setup. So the way it works is, I have a .csv file created
for each site that contains a header row, and then the printer info.
For example:

10.20.30.40,Xerox Phaser 6300N PS,PRINTER NAME,\\fileserver
\Printer_scripts\Printer_drivers\Xerox Phaser 6300DN PS\x6300_2k.inf

I then am able to drag and drop that .csv file onto the .vbs file and
it runs using that data.... (pretty cool feature I wasn't aware of
until recently).

Now, I'm not a "scripter" per se, so this script is probably pretty
slapped together... but it works and it's been a Godsend for me here
at work.

Here's the readme.txt I wrote to explain it:
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------
AUTOMATED TCP/IP Printer setup:

HOW IT WORKS:
The PRINTER_SCRIPT.VBS reads the information listed sequentially in
the .CSV file.
It installs the drivers (if listed), creates the port, adds the
printer, and names it.

You can install as many printers as you want.

Once done, a "Printer Setup Complete" message box appears.

----------------------------------------------------------------------
-----------------------

CUSTOMIZING THE PRINTER INFO .CSV FILE:

All customization of the script is done through .CSV files.

Open TEMPLATE_INFO.CSV with Excel or a text editor. Each row
represents a printer. Enter
the IP address, the driver name to be used, the name of the printer
(ie: Inventory room;
Sales floor, etc..), and the path to the printer's driver (.inf)
file, if it needs to be
loaded. Example: \\Server\share\printer drivers\xerox
\6250\x6250_2k.inf

If the driver is already included with XP (ie: HP LaserJet 4010
Series PS), you can just
leave the driver path blank. But, you still need to make sure you
enter the correct
driver name for that printer.

Save the file and name it whatever you want (ie: "main st
store.csv").
Just make sure it's a comma delimited format.


RUNNING THE IP_PRINTER_SETUP.VBS

To run the script, just drag-and-drop your .CSV file onto the
IP_printer_setup.vbs file as if
it were a file folder. This will run the script with the data
supplied in your .csv file.




Caveats:
- You *must* enter the *exact* driver name that you're loading.
To find this, you can either check on a machine with that same
model already
installed by clicking the advanced tab under the printer's
properties. Or, you
can open the proper driver file (.inf) in notepad and the drivers
are
usually listed under the section labeled with the manufacturer's
name in brackets.

Example:

[HP]
"HP LaserJet 4200 PCL 5e" = HPC42005.GPD, ...
"HP LaserJet 4200L PCL 5e" = HPC420X5.GPD, ...

But, this isn't *always* the case, so you may have to scroll around
the .inf file to
find the driver name you're looking to load.

**********************************************************
*** Do not use quotes anywhere in the PRINTER_INFO.CSV ***
**********************************************************

- The person running the script must have rights to install drivers
and ports.

- There's no need to load a driver twice. If you've got 2 Phaser
8400's,
you only need to map the path on the one listed *first* in the .CSV
file. Any
subsequent printers with the same driver name will use the already
installed driver.

- The file *must* be saved as a comma delimited .csv file!
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-------------------

And here is the actual script:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++
strComputer = "."

on error resume next

set objArgs = WScript.Arguments
set objFSO = CreateObject("Scripting.FileSystemObject")
set ipfile = objFSO.OpenTextFile(objArgs(0), 1)
set shell = WScript.CreateObject("WScript.Shell")
Set UserEnv = shell.Environment("USER")
Set FSO = CreateObject("Scripting.FileSystemObject")
Const WaitOnReturn = True
Const WindowStyle = 1

'read header row
data_in = ipfile.ReadLine

do until ipfile.AtEndOfStream

'Read data

data_in = split(ipfile.ReadLine,",")
port_ip = trim(data_in(0))
drvr_name = trim(data_in(1))
printer_name = trim(data_in(2))
drvr_path = trim(data_in(3))


'install driver if path listed

if drvr_path<>"" then
shell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /ia /c\\%computername% /
m """ & drvr_name &""" /h ""Intel"" /v ""Windows 2000 or XP"" /f """ &
drvr_path & """", WindowStyle, WaitOnReturn

end if

'Add Port

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

objNewPort.Name = "IP_" & port_ip
objNewPort.Protocol = 1
objNewPort.HostAddress = port_ip
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = True
objNewPort.Put_


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

Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

objPrinter.DriverName = drvr_name
objPrinter.PortName = "IP_" & port_ip
objPrinter.DeviceID = Printer_name
objPrinter.Network = True
objPrinter.Shared = False
objPrinter.Put_

'reset variables
port_ip=""
drvr_name=""
printer_name=""
drvr_path=""


loop

ipfile.Close
msgbox "Printer Setup Complete!"

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++

Good luck.. let me know how it turns out.


On Jan 24, 6:12 pm, "Jeremy Schubert" <jschubert@no*spam.shaw.ca>
wrote:
> Yes, please post the rest. Thanks."skipjack" <david.j.poehl...@cingular.com> wrote in messagenews:1169653749.355949.34860@l53g2000cwa.googlegroups.com...
>
>
>
> > This is what I had in mine to add the printer:
>
> > 'Add printer
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer &
> > "\root\cimv2")
>
> > Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
>
> > objPrinter.DriverName = drvr_name
> > objPrinter.PortName = "IP_" & port_ip
> > objPrinter.DeviceID = Printer_name
> > objPrinter.Network = True
> > objPrinter.Shared = False
> > objPrinter.Put_
>
> > My problem was loading drivers... I followed microsoft's example to
> > load printer drivers via vbscript.. but, it would go throught the
> > motions but not load the driver. I don't know if the problem was a
> > security issue or what.. so I wound up loading my drivers via a
> > rundll32 through a command shell. It works great now. Let me know if
> > you want me to post the rest.- Hide quoted text -- Show quoted text -