Jump to content

Recommended Posts

Posted

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


Posted

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?

Posted

I ran your script on my machine and had no problems at all. Even when some or all of he components were already installed I rcvd no errors.

I'd look at permission problems like cluberti suggested.

Posted

That didn't work.

Strange mmmm..

I will keep trying

If someone knows an other method of installing printers unattended.

Please let me know.

@ IcemanND and cluberti

Thanks for the quick reply and suggestions.

  • 1 month later...
Posted

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"

Posted

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 :).

Posted (edited)

@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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

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