Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 16th, 2009, 07:22 PM
Yerolo Yerolo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 1 Yerolo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 8 sec
Reputation Power: 0
VB script to add local printer (Vista)

Hi guys

hoping there is a VB scripting genius out there who can tell me why the script below does not work in Vista.

It works beautifully within XP (Havent tested on Win2k yet)

What this script does is:

1. Create a local tcp/ip port of 10.0.0.140
2. Install printer driver for Canon ir2020 to this port (the path of the driver files is referenced in the script)
3. Set as default printer

When running this script on a Vista machine, the following error appears:

"Windows Script Host

Error 87 adding printer driver Canon iR2020 UFRII LT"

Here is the contents of the vbscript:

Code:
Dim Computer, DriverName, DriverInf, IPAddress, PortName
Dim WMI, NewPort, NewDriver, NewPrinter

' BEGIN CALLOUT A
' BEGIN COMMENT
' Specify the computer on which to create the printer.
' END COMMENT
Computer = "."
' BEGIN COMMENT
' Specify the printer driver's name (take this from the INF file).
' END COMMENT
DriverName = "Canon iR2020 UFRII LT"
' BEGIN COMMENT
' Specify the .inf file's full path and filename.
' END COMMENT
DriverInf = "\Canon Driver\English\32BIT\win2k_vista\CNLB0K.INF"
' BEGIN COMMENT
' Specify the printer's IP address.
' END COMMENT
IPAddress = "10.0.0.140"
' END CALLOUT A

' BEGIN COMMENT
' Create the port name, then establish a WMI connection to the specified 
' computer. Note that the loaddriver privilege is required to add the driver.
' END COMMENT
PortName = "IP_" & IPAddress
Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate" _
  & ",(loaddriver)}!//" & Computer & "/root/cimv2")

' BEGIN COMMENT
' Step 1: Install the printer's driver.
' END COMMENT
Set NewDriver = WMI.Get("Win32_PrinterDriver")
NewDriver.Name = DriverName
NewDriver.InfName = DriverInf
Result = NewDriver.AddPrinterDriver(NewDriver)

If Result = 0 Then
  WScript.Echo "Added printer driver: " & DriverName
Else
  WScript.Echo "Error " & Result & " adding printer driver: " & DriverName
  WScript.Quit
End If

' BEGIN COMMENT
' Step 2: Create a TCP/IP printer port for the printer.
' END COMMENT
Set NewPort = WMI.Get("Win32_TCPIPPrinterPort").SpawnInstance_
NewPort.HostAddress = IPAddress
NewPort.Name = PortName
' BEGIN COMMENT
' Note that 1 = Raw, 2 = LPR
' END COMMENT
NewPort.Protocol = 1
NewPort.Put_
WScript.Echo "Created printer port: " & PortName

' BEGIN COMMENT
' Step 3: Add the printer.
' END COMMENT
Set NewPrinter = WMI.Get("Win32_Printer").SpawnInstance_
NewPrinter.DriverName = DriverName
NewPrinter.DeviceID = DriverName
NewPrinter.PortName = PortName
NewPrinter.Put_
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "Canon iR2020 UFRII LT"
WScript.Echo "Created printer: " & DriverName

Reply With Quote
  #2  
Old April 16th, 2009, 11:48 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,905 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 11 h 16 m 7 sec
Reputation Power: 969
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Try changing the protocol to LPR.

vb Code:
Original - vb Code
  1. NewPort.Protocol = 2
__________________
Don't like me? Click it.

Scripting problems? Windows questions? Ask the Windows Guru!

Stay up to date with all of my latest content. Follow me on Twitter!

Help us help you! Post your exact error message with these easy tips!

Reply With Quote
  #3  
Old May 20th, 2009, 08:59 PM
rapidfire rapidfire is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 1 rapidfire User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 45 sec
Reputation Power: 0
Talking script for vista

Quote:
Originally Posted by Yerolo
Hi guys

hoping there is a VB scripting genius out there who can tell me why the script below does not work in Vista.

It works beautifully within XP (Havent tested on Win2k yet)

What this script does is:

1. Create a local tcp/ip port of 10.0.0.140
2. Install printer driver for Canon ir2020 to this port (the path of the driver files is referenced in the script)
3. Set as default printer

When running this script on a Vista machine, the following error appears:

"Windows Script Host

Error 87 adding printer driver Canon iR2020 UFRII LT"

Here is the contents of the vbscript:

Code:
Dim Computer, DriverName, DriverInf, IPAddress, PortName
Dim WMI, NewPort, NewDriver, NewPrinter

' BEGIN CALLOUT A
' BEGIN COMMENT
' Specify the computer on which to create the printer.
' END COMMENT
Computer = "."
' BEGIN COMMENT
' Specify the printer driver's name (take this from the INF file).
' END COMMENT
DriverName = "Canon iR2020 UFRII LT"
' BEGIN COMMENT
' Specify the .inf file's full path and filename.
' END COMMENT
DriverInf = "\Canon Driver\English\32BIT\win2k_vista\CNLB0K.INF"
' BEGIN COMMENT
' Specify the printer's IP address.
' END COMMENT
IPAddress = "10.0.0.140"
' END CALLOUT A

' BEGIN COMMENT
' Create the port name, then establish a WMI connection to the specified 
' computer. Note that the loaddriver privilege is required to add the driver.
' END COMMENT
PortName = "IP_" & IPAddress
Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate" _
  & ",(loaddriver)}!//" & Computer & "/root/cimv2")

' BEGIN COMMENT
' Step 1: Install the printer's driver.
' END COMMENT
Set NewDriver = WMI.Get("Win32_PrinterDriver")
NewDriver.Name = DriverName
NewDriver.InfName = DriverInf
Result = NewDriver.AddPrinterDriver(NewDriver)

If Result = 0 Then
  WScript.Echo "Added printer driver: " & DriverName
Else
  WScript.Echo "Error " & Result & " adding printer driver: " & DriverName
  WScript.Quit
End If

' BEGIN COMMENT
' Step 2: Create a TCP/IP printer port for the printer.
' END COMMENT
Set NewPort = WMI.Get("Win32_TCPIPPrinterPort").SpawnInstance_
NewPort.HostAddress = IPAddress
NewPort.Name = PortName
' BEGIN COMMENT
' Note that 1 = Raw, 2 = LPR
' END COMMENT
NewPort.Protocol = 1
NewPort.Put_
WScript.Echo "Created printer port: " & PortName

' BEGIN COMMENT
' Step 3: Add the printer.
' END COMMENT
Set NewPrinter = WMI.Get("Win32_Printer").SpawnInstance_
NewPrinter.DriverName = DriverName
NewPrinter.DeviceID = DriverName
NewPrinter.PortName = PortName
NewPrinter.Put_
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "Canon iR2020 UFRII LT"
WScript.Echo "Created printer: " & DriverName





Thanks for the script as it made my life easier installing a bunch of IP Printers for users. I have used the same for Vista (x32 and x64). Though I'm not a real Script savvy, just changing the path of the drive details on the line " Driveinf = " made it work for me, and I have used it from a remote workstation. Hope this helps....


Raf

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > VB script to add local printer (Vista)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek