• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Windows 2000 TCP printer script

Skel

Diamond Member
I'm looking for a clue. Currently the place I work for is getting away from server base printing, and wants to move to TCP/IP printing. With WinXP I have a script that will both install the TCP/IP printer port and then install the printer, that one works great.

On the 2kPro the script doesn't work at all. I've looked around and the closest I've found is using the prnadmin.dll from the ResKit. Using the script from MS for it, the machine acts like the the printer port and printer are installed, but it won't connect to the printer. I've searched for a while and can't find any info on how to do this, if anyone has a clue please... please send it along.

Thanks for looking

Skel
 
Was wondering if you could clarify this.
Originally posted by: Skel
the closest I've found is using the prnadmin.dll from the ResKit. Using the script from MS for it, the machine acts like the the printer port and printer are installed, but it won't connect to the printer.

Also at my job we use tcp/ip printing in a win2k environment. I used the prnadmin.dll to add the drivers, ports and printers all from a vbscript. Kind of a pain but it works fine now.
The example here is what i used to get myself started.

Good luck :beer:
 
Thanks for the reply!!!!

I've set up a script using the Q page you mentioned. Just everytime I run the script it says it installs the port, and printer. When I fire off a test page to the print device it hangs for a second then errors out. When I install the printer, and port manually it works just fine. I'm not sure what I'm missing.. Could you drop me a copy of the script you use???

Thank for all the help!

SKel
 
OK here it is please note I hacked it up because I have more than 1 printer on the network. But I thought showing all of them would get confusing. So here you go. :beer: I am by no means a vbscript expert if you see something that could be done another way please let me know

The example is a HP laserjet 4100 with a Postscript Driver. The IP address of the printer is 192.168.1.200

'*******************
On Error Resume Next

Dim WshNetwork
Dim WshShell
Set WSHNetwork = WScript.CreateObject("WScript.Network")

'========= Register prnadmin.dll file on client computer ============
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run "net use x: \\server\share"
WshShell.Run "xcopy x:\prnadmin.dll %systemroot%\system32\ /D /R /Y",0,true
WshShell.Run "regsvr32 /s %systemroot%\system32\prnadmin.dll",0,TRUE

'====================================================================
'= Adding the printer drivers =
'====================================================================


'========= Check for printer driver HP 4100 PS ============

sKeyPathHP4100 = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3\HP LaserJet 4100 PS"
If RegKeyExists(sKeyPathHP4100) Then
'WScript.Echo "Key exists"
Else
'WScript.Echo "Key do not exist"
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run "rundll32 printui.dll,PrintUIEntry /ia /m ""HP LaserJet 4100 PS"" /h ""Intel"" /v ""Windows 2000"" /f x:\Drivers\hp4100ps\hp4100ps.inf /u" , 2 , true
End If




'====================================================================
'= Check for installed printers =
'====================================================================


Dim myPort_192_168_1_200

myPort_192_168_1_200 = 0

strComputer = "."

Set oSvc = GetObject("winmgmts:\\" & strComputer )
Set Printers = oSvc.Get("win32_printer").Instances_

default = false
for each printer in Printers

if printer.portname = "IP_192.168.1.200" then
myPort_192_168_1_200 = 1
else
'MsgBox "else:" &printer.name ,ok
End If

next

if myPort_192_168_1_200 <> 1 then
'====================================================================
'= HP4100 = 192.168.1.200 =
'====================================================================
'************** Create the port *************************************
dim oPort
dim oMaster
Set oPort = CreateObject("Port.Port.1")
Set oMaster = CreateObject("PrintMaster.PrintMaster.1")
oPort.PortName = "IP_192.168.1.200"
oPort.PortType = 1
oPort.HostAddress ="192.168.1.200"
oMaster.PortAdd oPort
if ErrHP4100 <> 0 then
msgbox "There was an error creating the port. 200"
end if
'********************************************************************
'************** Create the printer **********************************
dim oPrinter
Set oPrinter = CreateObject("Printer.Printer.1")
oPrinter.PrinterName = "HP4100" ' name of the printer as it appears in the Printers folder
oPrinter.DriverName = "HP LaserJet 4100 PS" ' name that is referenced in ntprint.inf or specific driver
oPrinter.PortName = "IP_192.168.1.200" ' Specify a port name. Can also point to LPT or COM port.
oMaster.PrinterAdd oPrinter
If ErrHP4100 <> 0 then
msgbox "There was an error creating the printer. 200"
end if
'********************************************************************

End If

WshShell.Run "net use x: /delete"


' --- Subroutine Check Registry for printer driver key-----------------

Function RegKeyExists(sRegKey)
Set oShell = CreateObject("WScript.Shell")
RegKeyExists = True
sRegKey = Trim (sRegKey)
If Not Right(sRegKey, 1) = "\" Then
sRegKey = sRegKey &amp; "\"
End if
On Error Resume Next
RegReadReturn = oShell.RegRead(sRegKey)
If Err Then
If LCase(Left(err.description,7)) = "invalid" Then
'key not found...
RegKeyExists = False
End if
Err.clear
End if
On Error Goto 0
End Function
 
Thank you soooo much!!!!!!

I was able to see where I was going wrong. Script is now working.

If you're ever in Phoenix drop me a line I owe you a beer!

Skel
 
Back
Top