Solved

trying to automatically install standard tcp/ip printers

Posted on 2008-10-29
2
875 Views
Last Modified: 2013-12-15
Hi Experts,

I am trying to connect to printers automatically on standard tcp/ip ports using a script.  I have researched this extensively and have seen several ways to do it.  The below code seemed to work well in its original state, I ran it and it installed the port and then installed Printer 1 on the port.  When  I entered my modifications, though I get errors, the most recent is Line 28 Char2 Error Genereic Failure Code 80041001 SWbemObjectEx.  I am willing to concede this may have to do with the driver which is the most current for the HP Color Laserjet 5550, not sure if it is signed.  How would I know?  Also when I unzipped it I loaded it directly to C:\HPCLJ5550.  The .inf and cab files are all in this folder.  What else do you need to know?  Help!

dim objWMIService
 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\.\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
 
 
Install "Printer Number 1", "HP Color LaserJet 5550", "C:\HPCLJ5550", "C:\HPCLJ5550\hpc5550d.inf", "172.25.8.41"
 
 
sub Install(strPrinter, strDriverName, strDriverSource, strDriverInf, strIP)
      ' Install the specified printer, including driver and port
      InstallPrinterDriver strDriverName, strDriverSource, strDriverInf
      InstallPrinterPort strIP
      InstallPrinter strPrinter, strDriverName, "IP_" & strIP
end sub
 
sub InstallPrinter(strName, strDriverName, strPortName)
      ' Install printer as detailed
      dim objPrinter : Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
 
      objPrinter.DriverName = strDriverName
      objPrinter.PortName   = strPortName '"IP_172.25.8.41"
      objPrinter.DeviceID   = strName
      objPrinter.Location = ""
      objPrinter.Network = True
      objPrinter.Shared = false
      objPrinter.Put_
end sub
 
sub InstallPrinterDriver(strDriverName, strDriverSource, strDriverInf)
      ' Installs the printer driver
      dim colInstalledDrivers, objDriver, strInstalledDriverName
      
      ' First check whether the driver is installed already
      Set colInstalledDrivers =  objWMIService.ExecQuery("Select Name from Win32_PrinterDriver")
      for each objDriver in colInstalledDrivers
            strInstalledDriverName=Left(objDriver.Name, Instr(1,objDriver.Name,",")-1)
            if strInstalledDriverName=strDriverName then exit sub ' We have a match, so no need to install driver
      next
      
      ' Driver not present, so install it
      Set objDriver = objWMIService.Get("Win32_PrinterDriver")
      objDriver.Name = strDriverName
      objDriver.SupportedPlatform = "Windows NT x86"
      objDriver.Version = "3"
      objDriver.DriverPath = strDriverSource
      objDriver.Infname = strDriverInf
      objDriver.AddPrinterDriver(objDriver)
end sub
 
sub InstallPrinterPort(strIP)
      ' First check whether the port exists already
      Set colInstalledPorts =  objWMIService.ExecQuery _
            ("Select Name from Win32_TCPIPPrinterPort")
      for each objPort in colInstalledPorts
            if objPort.Name="IP_" & strIP then exit sub ' We have a result, so no need to add port
      next
 
      ' Add new printer port
      Set objNewPort = objWMIService.Get _
            ("Win32_TCPIPPrinterPort").SpawnInstance_
      objNewPort.Name = "IP_" & strIP
      objNewPort.Protocol = 1
      objNewPort.HostAddress = strIP
      objNewPort.PortNumber = "9100"
      objNewPort.SNMPEnabled = False
      objNewPort.Put_
end sub
0
Comment
Question by:bfsharp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Author Comment

by:bfsharp
ID: 22845554
While waiting for an answer on this, I think I understand the problem.  In order to install TCP\IP printers one has to be an administrator.  The whole point of installing these printers, in such a manner, is that we have travelling staff and non-staff that transit throgh our building.  While here, they need to have print access but do not have server rights, thus they connect to printers via Standard TCP/IP Ports.  Manually configuring the ports and installing the printers is not problem at all.  The script, however, does not make the connection.  Is there a way to modify the script to ignore the administrator requirement?

Brian
0
 

Accepted Solution

by:
bfsharp earned 0 total points
ID: 22852097
Please close this question.  I did, finally figure out the problem and it has nothing to do with Administrator.  It seems that in all of my testing with various scripts trying to make this happen, one of the scripts was written to stop spooler service and then start spooler service.  Trouble was, the script didn't run far enough to restart the spooler service.  Once I manually restarted it I had no problem with the script I posted.

Thanks

Brian
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been scripting applications way too long and can never remember how to create an ISS file.  So I decided to write this article to act as my own knowledge base for future reference, and hope you will also benefit. An ISS file is a response …
Monitor input from a computer is usually nothing special.  In this instance it prevented anyone from using the computer.  This was a preconfiguration that didn't work.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question