Jump to content

Installing TCP/IP Printer


Recommended Posts

Hi all.

I've made a script that installs a TCP/IP port.

Then installs the printer that uses that port.

Adding the TCP/IP port works like a charm, but installing the printer not.

I've searched the net and my script should work. But it doesn't :(

The port is created before installing the printer.

I get this error message :

Line: 66

Char: 2

Error: Generic Failure

Code: 80041001

Source: SWbemObjectEx

I hope that someone knows the answer.

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_192.168.0.5"
objNewPort.Protocol = 2
objNewPort.HostAddress = "192.168.0.5"
objNewPort.PortNumber = "515"
objNewPort.Queue = "LPT1_PASSTHRU"
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 deskjet 990c"
' objDriver.SupportedPlatform = "Windows NT x86"
' objDriver.Version = "3"
' objDriverPath = "C:\WINNT\System32\Printui.dll"
' objInfname = "C:\WINNT\inf\ntprint.inf"
' 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 deskjet 990c"
objPrinter.PortName = "IP_192.168.0.5"
objPrinter.DeviceID = "HP DeskJet 990CXi"
objPrinter.Network = True
objPrinter.Shared = False
objPrinter.ShareName = ""
objPrinter.Published = False
objPrinter.Location = "@ LAN"
objPrinter.Put_

Wscript.Quit

Link to comment
Share on other sites


That's a pretty generic error, but it usually points to a permissions or firewall problem. Since I'm assuming it's not a firewall problem, have you checked to make sure that the spooler service really did restart? What about the RPC services - are they all running?

Link to comment
Share on other sites

  • 1 month later...

Please could you point out the things that are needed to be changed for this to work?

I looked into it abit and figured out some of them, but I'm abit unsure... does the drivers need to be installed before running this script?

Are these general Windows files or driver files?

' objDriverPath = "C:\WINNT\System32\Printui.dll"

' objInfname = "C:\WINNT\inf\ntprint.inf"

Link to comment
Share on other sites

If you can get the printer installed on another machine, you can use the printmig tool to move the printer and the ports over to any number of other machines. I know it isn't as pretty as a vbscript, but it does work :).

Link to comment
Share on other sites

@cluberti:

Microsoft printmig.exe RULES!

Beware there is a commercial product that does about the same with the same name... dont buy that! Just use the Microsoft tool thats free - its works perfectly!

Edited by druiddk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...