I'm looking for a script that will map a printer based on ip address and also
will assign it the generic laserjet 5 driver.

For example if the print server goes down, a script to execute that will add
the port number ip_192.168.1.x using the laserjet 5 print driver and possibly
setting it as the default.

Any ideas? This needs to work on XP and Windows 2000 pcs. If this can be
done via batch file, let me know.

Thanks.

Re: script to map tcp/ip printer by Tom

Tom
Tue May 06 08:46:25 CDT 2008

On May 5, 5:39 pm, pete0085 <pete0...@discussions.microsoft.com>
wrote:
> I'm looking for a script that will map a printer based on ip address and also
> will assign it the generic laserjet 5 driver.
>
> For example if the print server goes down, a script to execute that will add
> the port number ip_192.168.1.x using the laserjet 5 print driver and possibly
> setting it as the default.
>
> Any ideas? This needs to work on XP and Windows 2000 pcs. If this can be
> done via batch file, let me know.
>
> Thanks.

Don't really know this stuff, but note that there are examples in the
MS Technet Script Center example library ...

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

' Connect to IP printer
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = "IP_169.254.110.14"
objNewPort.Protocol = 1
objNewPort.HostAddress = "169.254.110.14"
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_

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

objDriver.Name = "Apple LaserWriter 8500"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
errResult = objDriver.AddPrinterDriver(objDriver)

' Set as default
CreateObject("WScript.Network").SetDefaultPrinter objNewPort.Name

The library is decidedly sparse when it comes to details about how to
adapt to your own situation, so you're on your own in that regard. I
guess they figure that now that you know what you're looking for, you
can go look up the documentation.

HTH,

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: script to map tcp/ip printer by pete0085

pete0085
Tue May 06 14:16:02 CDT 2008

Where did you get this script from? It wasn't working, but it may not be set
up correctly or replacing all the require values in quotes.

It cannot find the printer ip_xxx.xxx.xxx on line 28.

"Tom Lavedas" wrote:

> On May 5, 5:39 pm, pete0085 <pete0...@discussions.microsoft.com>
> wrote:
> > I'm looking for a script that will map a printer based on ip address and also
> > will assign it the generic laserjet 5 driver.
> >
> > For example if the print server goes down, a script to execute that will add
> > the port number ip_192.168.1.x using the laserjet 5 print driver and possibly
> > setting it as the default.
> >
> > Any ideas? This needs to work on XP and Windows 2000 pcs. If this can be
> > done via batch file, let me know.
> >
> > Thanks.
>
> Don't really know this stuff, but note that there are examples in the
> MS Technet Script Center example library ...
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> ' Connect to IP printer
> Set objNewPort = objWMIService.Get _
> ("Win32_TCPIPPrinterPort").SpawnInstance_
>
> objNewPort.Name = "IP_169.254.110.14"
> objNewPort.Protocol = 1
> objNewPort.HostAddress = "169.254.110.14"
> objNewPort.PortNumber = "9999"
> objNewPort.SNMPEnabled = False
> objNewPort.Put_
>
> ' Load driver
> Set objDriver = objWMIService.Get("Win32_PrinterDriver")
> objWMIService.Security_.Privileges.AddAsString _
> "SeLoadDriverPrivilege", True
>
> objDriver.Name = "Apple LaserWriter 8500"
> objDriver.SupportedPlatform = "Windows NT x86"
> objDriver.Version = "3"
> errResult = objDriver.AddPrinterDriver(objDriver)
>
> ' Set as default
> CreateObject("WScript.Network").SetDefaultPrinter objNewPort.Name
>
> The library is decidedly sparse when it comes to details about how to
> adapt to your own situation, so you're on your own in that regard. I
> guess they figure that now that you know what you're looking for, you
> can go look up the documentation.
>
> HTH,
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
>

Re: script to map tcp/ip printer by pete0085

pete0085
Tue May 06 14:49:06 CDT 2008

Here is what I am trying, getting the error on line 23 , "there is no printer
called "ip_198.213.xx.x". Code 80020009

If I'm correct, the first part should create the port, which it does. Not
sure what I'm missing. Anyone else have any ideas??

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

' Connect to IP printer
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = "IP_198.213.XX.X"
objNewPort.Protocol = 1
objNewPort.HostAddress = "198.213.XX.X"
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_

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

objDriver.Name = "HP LaserJet 4"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "5"
errResult = objDriver.AddPrinterDriver(objDriver)

' Set as default
CreateObject("WScript.Network").SetDefaultPrinter objNewPort.Name

Re: script to map tcp/ip printer by James

James
Tue May 06 19:58:10 CDT 2008

"pete0085" <pete0085@discussions.microsoft.com> wrote in message
news:971753B2-288E-4136-91A1-DC9AD18E4ADF@microsoft.com...
> Here is what I am trying, getting the error on line 23 , "there is no
> printer
> called "ip_198.213.xx.x". Code 80020009
>
> If I'm correct, the first part should create the port, which it does. Not
> sure what I'm missing. Anyone else have any ideas??
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> ' Connect to IP printer
> Set objNewPort = objWMIService.Get _
> ("Win32_TCPIPPrinterPort").SpawnInstance_
>
> objNewPort.Name = "IP_198.213.XX.X"
> objNewPort.Protocol = 1
> objNewPort.HostAddress = "198.213.XX.X"
> objNewPort.PortNumber = "9100"
> objNewPort.SNMPEnabled = False
> objNewPort.Put_
>
> ' Load driver
> Set objDriver = objWMIService.Get("Win32_PrinterDriver")
> objWMIService.Security_.Privileges.AddAsString _
> "SeLoadDriverPrivilege", True
>
> objDriver.Name = "HP LaserJet 4"
> objDriver.SupportedPlatform = "Windows NT x86"
> objDriver.Version = "5"
> errResult = objDriver.AddPrinterDriver(objDriver)
>
> ' Set as default
> CreateObject("WScript.Network").SetDefaultPrinter objNewPort.Name

I found a rundll sample here:

http://www.robvanderwoude.com/2kprintcontrol.html

I used it to modify your code. It works on my computer. Give it a try:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set oWSH = CreateObject("WScript.Shell")

sPortIP = "198.213.XX.X"
sPortName = "IP_198.213.XX.X"
sPrtName = "HP LaserJet 4"
sPrtDriver = "HP LaserJet 4"
strComputer = "."

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

' Connect to IP printer
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = sPortName
objNewPort.Protocol = 1
objNewPort.HostAddress = sPortIP
objNewPort.PortNumber = 9100
objNewPort.SNMPEnabled = False
objNewPort.Put_

' Install the printer
oWSH.Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
& sPrtName & """" & " /f %windir%\inf\ntprint.inf /r " _
& sPortName & " /m """ & sPrtDriver & """", 0, True

' Set as default
CreateObject("WScript.Network").SetDefaultPrinter objNewPort.Name
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Re: script to map tcp/ip printer by pete0085

pete0085
Wed May 07 13:12:01 CDT 2008

Thanks. That works fine, but wasn't working on a Windows 2000 pc. I found a
similar script yesterday that worked for me, but that doesn't work on Windows
2000 either.

I also had a power user try to run the script with an access denied message.
I am guessing this is a windows limitation where a power user cannot add a
port or add a printer that is not a plug n play printer. Users had full
control to that script. Is there a way around this or would I need to use a
startup script to push this out to a pc?

"James Whitlow" wrote:

> "pete0085" <pete0085@discussions.microsoft.com> wrote in message
> news:971753B2-288E-4136-91A1-DC9AD18E4ADF@microsoft.com...
> > Here is what I am trying, getting the error on line 23 , "there is no
> > printer
> > called "ip_198.213.xx.x". Code 80020009
> >
> > If I'm correct, the first part should create the port, which it does. Not
> > sure what I'm missing. Anyone else have any ideas??
> >
> > strComputer = "."
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" _
> > & strComputer & "\root\cimv2")
> >
> > ' Connect to IP printer
> > Set objNewPort = objWMIService.Get _
> > ("Win32_TCPIPPrinterPort").SpawnInstance_
> >
> > objNewPort.Name = "IP_198.213.XX.X"
> > objNewPort.Protocol = 1
> > objNewPort.HostAddress = "198.213.XX.X"
> > objNewPort.PortNumber = "9100"
> > objNewPort.SNMPEnabled = False
> > objNewPort.Put_
> >
> > ' Load driver
> > Set objDriver = objWMIService.Get("Win32_PrinterDriver")
> > objWMIService.Security_.Privileges.AddAsString _
> > "SeLoadDriverPrivilege", True
> >
> > objDriver.Name = "HP LaserJet 4"
> > objDriver.SupportedPlatform = "Windows NT x86"
> > objDriver.Version = "5"
> > errResult = objDriver.AddPrinterDriver(objDriver)
> >
> > ' Set as default
> > CreateObject("WScript.Network").SetDefaultPrinter objNewPort.Name
>
> I found a rundll sample here:
>
> http://www.robvanderwoude.com/2kprintcontrol.html
>
> I used it to modify your code. It works on my computer. Give it a try:
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Set oWSH = CreateObject("WScript.Shell")
>
> sPortIP = "198.213.XX.X"
> sPortName = "IP_198.213.XX.X"
> sPrtName = "HP LaserJet 4"
> sPrtDriver = "HP LaserJet 4"
> strComputer = "."
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> ' Connect to IP printer
> Set objNewPort = objWMIService.Get _
> ("Win32_TCPIPPrinterPort").SpawnInstance_
>
> objNewPort.Name = sPortName
> objNewPort.Protocol = 1
> objNewPort.HostAddress = sPortIP
> objNewPort.PortNumber = 9100
> objNewPort.SNMPEnabled = False
> objNewPort.Put_
>
> ' Install the printer
> oWSH.Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
> & sPrtName & """" & " /f %windir%\inf\ntprint.inf /r " _
> & sPortName & " /m """ & sPrtDriver & """", 0, True
>
> ' Set as default
> CreateObject("WScript.Network").SetDefaultPrinter objNewPort.Name
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>

Re: script to map tcp/ip printer by James

James
Wed May 07 13:56:13 CDT 2008

"pete0085" <pete0085@discussions.microsoft.com> wrote in message
news:52F7A7B9-6717-4F2B-BBBA-C36908CDF09A@microsoft.com...
> Thanks. That works fine, but wasn't working on a Windows 2000 pc. I
> found a
> similar script yesterday that worked for me, but that doesn't work on
> Windows
> 2000 either.
>
> I also had a power user try to run the script with an access denied
> message.
> I am guessing this is a windows limitation where a power user cannot add a
> port or add a printer that is not a plug n play printer. Users had full
> control to that script. Is there a way around this or would I need to use
> a
> startup script to push this out to a pc?

Interesting. When I originally tested it, I was logged in with
administrative privileges, but I just tried it on another computer for which
I am logged in as a power user and it completed successfully. In fact, there
was already a printer named 'HP LaserJet 4' and Windows automatically called
the new one 'HP LaserJet 4 (Copy 1)'.

I thought maybe your error might have been caused by the port already
existing, but I ran the script a second time without deleting the first
printer or the port and I got 'HP LaserJet 4 (Copy 2)' connected to the
existing port. It did not complain about the port already existing.

I no longer have a Windows 2000 computer at my disposal, so I cannot
test it in that environment. What type of error / failure do you get when
running the script in Windows 2000? Have you tried the script on more than
one Windows 2000 machine just to be sure there is not someting wrong with
that specific computer?



Re: script to map tcp/ip printer by pete0085

pete0085
Wed May 07 14:44:07 CDT 2008


I only tried it on one windows 2000 pc. We only have 4 in our organization
so I'm not too worried about that.

The access denied message is occuring on both scripts (let me know if you
want me paste my second script) and it's occuring at line 22, char 1. They
both have one item in common; ObjNewPort.put_

It's giving me an access denied at that code on both scripts. It runs fine
as an administrator. The ports were not previously created. I also tried it
with the printers and ports already installed and the same error.

As mentioned earlier think the main reason is when I try to add a printer as
a power user, the only option available is a network printer. Sounds like I
don't have access to create a port and that would make sense. I could be
wrong, but sounds like the best explanation.
>
> Interesting. When I originally tested it, I was logged in with
> administrative privileges, but I just tried it on another computer for which
> I am logged in as a power user and it completed successfully. In fact, there
> was already a printer named 'HP LaserJet 4' and Windows automatically called
> the new one 'HP LaserJet 4 (Copy 1)'.
>
> I thought maybe your error might have been caused by the port already
> existing, but I ran the script a second time without deleting the first
> printer or the port and I got 'HP LaserJet 4 (Copy 2)' connected to the
> existing port. It did not complain about the port already existing.
>
> I no longer have a Windows 2000 computer at my disposal, so I cannot
> test it in that environment. What type of error / failure do you get when
> running the script in Windows 2000? Have you tried the script on more than
> one Windows 2000 machine just to be sure there is not someting wrong with
> that specific computer?
>
>
>

Re: script to map tcp/ip printer by Tom

Tom
Wed May 07 14:59:10 CDT 2008

On May 7, 2:56 pm, "James Whitlow" <jwhitlow.60372...@bloglines.com>
wrote:
> "pete0085" <pete0...@discussions.microsoft.com> wrote in message
>
> news:52F7A7B9-6717-4F2B-BBBA-C36908CDF09A@microsoft.com...
>
> > Thanks. That works fine, but wasn't working on a Windows 2000 pc. I
> > found a
> > similar script yesterday that worked for me, but that doesn't work on
> > Windows
> > 2000 either.
>
> > I also had a power user try to run the script with an access denied
> > message.
> > I am guessing this is a windows limitation where a power user cannot add a
> > port or add a printer that is not a plug n play printer. Users had full
> > control to that script. Is there a way around this or would I need to use
> > a
> > startup script to push this out to a pc?
>
{snip}
> I no longer have a Windows 2000 computer at my disposal, so I cannot
> test it in that environment. What type of error / failure do you get when
> running the script in Windows 2000? Have you tried the script on more than
> one Windows 2000 machine just to be sure there is not someting wrong with
> that specific computer?

I went back to the Script Center samples and realized that the neither
of the two WMI classes I originally posted to map and install the
driver are supported in Win2K. Sorry, I didn't note that as a need or
as a restriction.

The rundll32 approach for loading the driver should work in both
environments, but I seem to remember there are some differences
between the versions of the printui.dll in the two OSs.

Upon further examination, it would appear that if you use the rundll
approach, the whole thing can be done in one pass, without the WMI
call or the later WScript.Shell to set teh default. This should be
accomplished with the addition of a /c\\192.312..XX.X switch for the
port address and /y switch to set the printer as the default. Oh, and
for the mixed machine environment, you'll want to add a /v[version]
switch as well.

sPortIP = "198.213.XX.X"
sPortName = "IP_198.213.XX.X"
sPrtName = "HP LaserJet 4"
sPrtDriver = "HP LaserJet 4"

' Install the printer
oWSH.Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
& sPrtName & """ /c\\" & sPortIP & " /f %windir%\inf\ntprint.inf /r "
_
& sPortName & " /m """ & sPrtDriver _
& """ /v ""Windows 2000 or XP"" /y", 0, True

For more very brief usage explanations and some examples type

rundll32 printui.dll,PrintUIEntry /?

at a command prompt or in the Start/Run dialog box. It pops up a GUI,
from which the text can be cut and pasted for later reference.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: script to map tcp/ip printer by pete0085

pete0085
Wed May 07 15:30:01 CDT 2008

Ok, not sure what I typed in wrong, but nothing happened this time. I took
your advice and I'll post what I have.
et oWSH = CreateObject("WScript.Shell")

sPortIP = "198.213.xx.x
sPortName = "IP_198.213.xx.x"
sPrtName = "Printer Test"
sPrtDriver = "HP LaserJet 4"
strComputer = "."

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

' Connect to IP printer
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = sPortName
objNewPort.Protocol = 1
objNewPort.HostAddress = sPortIP
objNewPort.PortNumber = 9100
objNewPort.SNMPEnabled = False
objNewPort.Put_

' Install the printer
oWSH.Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
& sPrtName & """/c\\" & sPortIP & "/f %windir%\inf\ntprint.inf

/r " _
& sPortName & " /m """ & sPrtDriver & """/v ""Windows 2000 or

XP"" /y", 0, True

' Set as default
CreateObject("WScript.Network").SetDefaultPrinter

objNewPort.Name



> I went back to the Script Center samples and realized that the neither
> of the two WMI classes I originally posted to map and install the
> driver are supported in Win2K. Sorry, I didn't note that as a need or
> as a restriction.
>
> The rundll32 approach for loading the driver should work in both
> environments, but I seem to remember there are some differences
> between the versions of the printui.dll in the two OSs.
>
> Upon further examination, it would appear that if you use the rundll
> approach, the whole thing can be done in one pass, without the WMI
> call or the later WScript.Shell to set teh default. This should be
> accomplished with the addition of a /c\\192.312..XX.X switch for the
> port address and /y switch to set the printer as the default. Oh, and
> for the mixed machine environment, you'll want to add a /v[version]
> switch as well.
>
> sPortIP = "198.213.XX.X"
> sPortName = "IP_198.213.XX.X"
> sPrtName = "HP LaserJet 4"
> sPrtDriver = "HP LaserJet 4"
>
> ' Install the printer
> oWSH.Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
> & sPrtName & """ /c\\" & sPortIP & " /f %windir%\inf\ntprint.inf /r "
> _
> & sPortName & " /m """ & sPrtDriver _
> & """ /v ""Windows 2000 or XP"" /y", 0, True
>
> For more very brief usage explanations and some examples type
>
> rundll32 printui.dll,PrintUIEntry /?
>
> at a command prompt or in the Start/Run dialog box. It pops up a GUI,
> from which the text can be cut and pasted for later reference.
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
>

Re: script to map tcp/ip printer by Tom

Tom
Wed May 07 16:20:35 CDT 2008

On May 7, 4:30 pm, pete0085 <pete0...@discussions.microsoft.com>
wrote:
> Ok, not sure what I typed in wrong, but nothing happened this time. I took
> your advice and I'll post what I have.
{snip}

NO!! I meant that ALL you needed was JUST THE CODE I POSTED, not that
it replaced the rundll part of the old code. However, there was an
added problem in that some of the lines I posted clearly wrapped in
transit (Oh, and I forgot the Shell creation line).

Try this ...

'--------------- Start of code ------------------
sPortIP = "198.213.XX.X"
sPortName = "IP_198.213.XX.X"
sPrtName = "HP LaserJet 4"
sPrtDriver = "HP LaserJet 4"

' Install the printer, connect the printer and set it as default
CreateObject("Wscript.Shell")_
.Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
& sPrtName & """ /c\\" & sPortIP _
& " /f %windir%\inf\ntprint.inf /r "_
& sPortName & " /m """ & sPrtDriver _
& """ /v ""Windows 2000 or XP"" /y", 0, True
'--------------- End of code ------------------

Use this as is, and ONLY this, except for correcting the IP address to
the actual ones your printer is on.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: script to map tcp/ip printer by James

James
Thu May 08 13:19:41 CDT 2008

"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:b7777d0c-e2a1-4e3a-bb8c-428de2e8d65c@w7g2000hsa.googlegroups.com...
> On May 7, 4:30 pm, pete0085 <pete0...@discussions.microsoft.com>
> wrote:
>> Ok, not sure what I typed in wrong, but nothing happened this time. I
>> took
>> your advice and I'll post what I have.
> {snip}
>
> NO!! I meant that ALL you needed was JUST THE CODE I POSTED, not that
> it replaced the rundll part of the old code. However, there was an
> added problem in that some of the lines I posted clearly wrapped in
> transit (Oh, and I forgot the Shell creation line).
>
> Try this ...
>
> '--------------- Start of code ------------------
> sPortIP = "198.213.XX.X"
> sPortName = "IP_198.213.XX.X"
> sPrtName = "HP LaserJet 4"
> sPrtDriver = "HP LaserJet 4"
>
> ' Install the printer, connect the printer and set it as default
> CreateObject("Wscript.Shell")_
> .Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
> & sPrtName & """ /c\\" & sPortIP _
> & " /f %windir%\inf\ntprint.inf /r "_
> & sPortName & " /m """ & sPrtDriver _
> & """ /v ""Windows 2000 or XP"" /y", 0, True
> '--------------- End of code ------------------
>
> Use this as is, and ONLY this, except for correcting the IP address to
> the actual ones your printer is on.

Tom, I tried this on 2 different XP Pro computers (admin on one, power
user on the other). In both cases, nothing happened.



Re: script to map tcp/ip printer by Tom

Tom
Thu May 08 15:35:03 CDT 2008

On May 8, 2:19 pm, "James Whitlow" <jwhitlow.60372...@bloglines.com>
wrote:
> "Tom Lavedas" <tglba...@cox.net> wrote in message
>
> news:b7777d0c-e2a1-4e3a-bb8c-428de2e8d65c@w7g2000hsa.googlegroups.com...
>
>
>
> > On May 7, 4:30 pm, pete0085 <pete0...@discussions.microsoft.com>
> > wrote:
> >> Ok, not sure what I typed in wrong, but nothing happened this time. I
> >> took
> >> your advice and I'll post what I have.
> > {snip}
>
> > NO!! I meant that ALL you needed was JUST THE CODE I POSTED, not that
> > it replaced the rundll part of the old code. However, there was an
> > added problem in that some of the lines I posted clearly wrapped in
> > transit (Oh, and I forgot the Shell creation line).
>
> > Try this ...
>
> > '--------------- Start of code ------------------
> > sPortIP = "198.213.XX.X"
> > sPortName = "IP_198.213.XX.X"
> > sPrtName = "HP LaserJet 4"
> > sPrtDriver = "HP LaserJet 4"
>
> > ' Install the printer, connect the printer and set it as default
> > CreateObject("Wscript.Shell")_
> > .Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
> > & sPrtName & """ /c\\" & sPortIP _
> > & " /f %windir%\inf\ntprint.inf /r "_
> > & sPortName & " /m """ & sPrtDriver _
> > & """ /v ""Windows 2000 or XP"" /y", 0, True
> > '--------------- End of code ------------------
>
> > Use this as is, and ONLY this, except for correcting the IP address to
> > the actual ones your printer is on.
>
> Tom, I tried this on 2 different XP Pro computers (admin on one, power
> user on the other). In both cases, nothing happened.

I'm a little out of my depth here. I started with the rundll
statement that you reported as functioning before. The printUI
documentation and the groups.google search examples suggested that the
changes I added should finish the job, but also indicated it was
tricky to get everything just right.

Maybe you can you run it at a command prompt (as a batch procedure) to
see what, if any error codes might be thrown? Remove the /q switch so
that it displays errors. I would do it, but my corporate network
structure makes IP mapping difficult (at least for me). We map ours
for ourselves through a web portal (with persistence). They are not
mapped at login for us.

Now that I look at the statement again, I wonder if there isn't an
error. The /r switch parameter is coded as the PortName, when I think
this might be reserved for the the port address, as in "9100". I
would think the /n switch is used instead to specify the name.

Maybe ...

'--------------- Start of code ------------------
sPortIP = "198.213.XX.X"
sPortName = "IP_198.213.XX.X"
sPrtName = "HP LaserJet 4"
sPrtDriver = "HP LaserJet 4"

' Install the printer, connect the printer and set it as default
CreateObject("Wscript.Shell")_
.Run "rundll32 printui.dll,PrintUIEntry /q /if /b """ _
& sPrtName & """ /c\\" & sPortIP _
& " /f %windir%\inf\ntprint.inf /n "_
& sPortName & " /m """ & sPrtDriver _
& """ /v ""Windows 2000 or XP"" /y", 0, True
'--------------- End of code ------------------

I don't know and really don't have the facilities to test, so maybe I
should just shut my trap now, before I get behinder 8^}

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: script to map tcp/ip printer by pete0085

pete0085
Sat May 10 12:51:01 CDT 2008

Thanks for trying. The only problem is working on Windows 2000. I probably
could do this manually. Here is the script I use for all the other ones. It
works great, just need to figure out the correct printer driver. Often it
prints out garbage. Also figured out the power user permisson problems.
There was a gpo setting under user rights assesment.

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

'Install TCP/IP Port :

Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = "IP_198.213.xx.x"
objNewPort.Protocol = 1
objNewPort.HostAddress = "198.213.xx.x"
objNewPort.PortNumber = "9100"
objNewPort.Queue = ""
objNewPort.SNMPCommunity = "public"
objNewPort.SNMPEnabled = False
objNewPort.Put_

'Stop Spooler Service

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='Spooler'")
For Each objService In colServiceList
errReturn = objService.StopService()
WScript.Sleep 5000
Next

'Start Spooler Service

For Each objService In colServiceList
errReturn = objService.StartService()
WScript.Sleep 5000
Next

'Install Driver :
'
' objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege",
True
'
' Set objDriver = objWMIService.Get("Win32_PrinterDriver")
'
' objDriver.Name = "HP LaserJet 5"
' objDriver.SupportedPlatform = "Windows NT x86"
' objDriver.Version = "5"
' objDriverPath = ""
' objInfname = ""
' intResult = objDriver.AddPrinterDriver(objDriver)
'
'Install TCP-Printer :

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

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

objPrinter.DriverName = "HP LaserJet 5"
objPrinter.PortName = "IP_198.213.xx.x"
objPrinter.DeviceID = "Branch1 Backup Printer"
objPrinter.Network = True
objPrinter.Shared = False
objPrinter.ShareName = ""
objPrinter.Published = False
objPrinter.Location = "Branch1 Backup"
objPrinter.Put_

CreateObject("WScript.Network").SetDefaultPrinter objNewPort.Name

Wscript.Quit

>
> I don't know and really don't have the facilities to test, so maybe I
> should just shut my trap now, before I get behinder 8^}
>
> Tom Lavedas
> ===========