
May 20th, 2009, 08:59 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 1
Time spent in forums: 30 m 45 sec
Reputation Power: 0
|
|
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
|