• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

I need a vbscript for to add printers locally in a Server '08, XP environment

I have approximately 20 groups that map around 3 to 4 printers each. I will want each printer to install locally by IP and to ignore copying over the driver if the printer already exists. I am new to vbscript so please also explain how to modify the script for multiple printers if applicable (obviously will depend on how the script is written)

Again, thanks for your help in advance.
0
bwiser1
Asked:
bwiser1
  • 5
  • 5
1 Solution
 
x-menIT super heroCommented:
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
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_
      
0
 
bwiser1Author Commented:
x-men,

Thanks for the script and the prompt comment. Could you elaborate on this a bit? I am new and a working understanding would be much appreciated. Thank you for your assistance.
0
 
x-menIT super heroCommented:
the script installs a TCP/IP printer port on a computer.

after you can install the printer on that por:

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

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

objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName   = "IP_169.254.110.160"
objPrinter.DeviceID   = "ScriptedPrinter"
objPrinter.Location = "USA/Redmond/Building 37/Room 114"
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = "ScriptedPrinter"
objPrinter.Put_
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
x-menIT super heroCommented:
putting it all together:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
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_

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

objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName   = "IP_169.254.110.14"
objPrinter.DeviceID   = "ScriptedPrinter"
objPrinter.Location = "USA/Redmond/Building 37/Room 114"
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = "ScriptedPrinter"
objPrinter.Put_

Open in new window

0
 
bwiser1Author Commented:
x-men,

Thank you. I thought that's what I was reading, but it's nice to know that I was right. Long road ahead with VBScript, but well worth the interest. Thank you for your assistance. I'll try a few printers and let you know if I run into any problems.

0
 
x-menIT super heroCommented:
0
 
bwiser1Author Commented:
x-men was fantastic. I posted my question and within an hour I would say, he had responded. The above solution did exactly what I was hoping and now that I have created all my groups, I have verified his answer was perfect. Well done. A+
0
 
bwiser1Author Commented:
One last question. If I were to want to reference a network location for the drivers by IP\share, would there be a simple way to do that also within this script?
0
 
x-menIT super heroCommented:
Installs a hypothetical printer using a print driver not found in Drivers.cab:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True

Set objDriver = objWMIService.Get("Win32_PrinterDriver")

objDriver.Name = "NewPrinter Model 2900"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
objDriverPath = "C:\Scripts\NewPrinter.dll"
objInfname = "C:\Scripts\NewPrinter.inf"
intResult = objDriver.AddPrinterDriver(objDriver)

Open in new window

0
 
bwiser1Author Commented:
x-men,

Thank you for the quick response. I looked over your last reply and I'm not sure I explained exactly. Essentially, the first script you sent me looks to the repository on the local machine. I created those and all went well. However, as we delete/update printers/drivers I was curious if there was a fairly easy way to add a line or two so that it can reference a network share by IP so that it would know where to go should the driver not be there.

Thanks for your patience, as I said earlier, I am a bit thick when it comes to VBScript. A bit at a time...

Thanks again for all your help.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now