themadkat
05-30-2002, 09:52 PM
I am trying to create a script that will check for an installed printer, and if it doesn't exist, install it. I would like to place this script in a GP on the Computer Configuration---Startup Script for an OU.
I can run the script manually and it does everything I need it to do. But, when it is processed during GP startup, I receive an error message:
Title: Windows Scripting Host
Line: 27 Char: 5 Error: The System cannot find the file specified.
Code: 80070002 Source: (null)
Here is the code:
Dim Flag, Printer1
Flag = "No"
Printer1 = "\\server\printer"
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
i = 1
Do While i <= oPrinters.Count
If oPrinters.Item(i) = Printer1 Then Flag = "Yes"
End If
i = i + 2 Loop
If Flag = "No" Then
WshNetwork.AddWindowsPrinterConnection "\\server\printer"
End If
This is my first script to ever write, where did I go wrong. I don't understand how it will work manually, but not by the GP. I have taken the "WshNetwork.AddWindowsPrinterConnection" line and it didn't give me the error. Obviously that is the problem, but that is the main objective of the program. How can I fix it?
Thank you! John Herrmann
I can run the script manually and it does everything I need it to do. But, when it is processed during GP startup, I receive an error message:
Title: Windows Scripting Host
Line: 27 Char: 5 Error: The System cannot find the file specified.
Code: 80070002 Source: (null)
Here is the code:
Dim Flag, Printer1
Flag = "No"
Printer1 = "\\server\printer"
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
i = 1
Do While i <= oPrinters.Count
If oPrinters.Item(i) = Printer1 Then Flag = "Yes"
End If
i = i + 2 Loop
If Flag = "No" Then
WshNetwork.AddWindowsPrinterConnection "\\server\printer"
End If
This is my first script to ever write, where did I go wrong. I don't understand how it will work manually, but not by the GP. I have taken the "WshNetwork.AddWindowsPrinterConnection" line and it didn't give me the error. Obviously that is the problem, but that is the main objective of the program. How can I fix it?
Thank you! John Herrmann