Re: WSH error help
- From: "Linn Kubler" <lkubler@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 8 Apr 2008 17:51:27 -0500
"Tom Lavedas" <tglbatch@xxxxxxx> wrote in message
news:b793bf52-711e-460f-9d77-427ce87ef400@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Apr 8, 12:03 pm, "Linn Kubler" <lkub...@xxxxxxxxxxxxxxxxxx> wrote:
Hi,
Trying to write a script that will take a list of computers from a file,
stop the spooler process, remove a printer and then start the spooler
process again. My printers were all added using the rundll32 printui,
PrintUIEntry command run at each workstation. Now I'm tring to simplify
the
task of removing an obsolete printer. But I'm getting an error and
wondering if anyone can help sort it out.
The error reads:
Windows Scripting Host
Script: c:\remote_printer_cleanup_install.vbs
Line: 39
Char: 45
Error: Syntax error
Code: 800A03EA
Source: Microsoft VBScript compilation error
Here's my script:
' =====================================================================
' remote_printer_cleanup_install.vbs
' =====================================================================
On Error Resume Next
Const ForReading = 1
Const WbemAuthenticationLevelPktPrivacy = 6
strUser = "Administrator"
strPassword = "domainadminpassword"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(".\computers.txt", ForReading)
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
' strComputerUser = "Computer" & vbTab & "Logged in User"
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
' =====================================================================
' Insert your code here
' =====================================================================
Set objWMIService = objwbemLocator.ConnectServer (strComputer,
strNamespace, strUser, strPassword)
objWMIService.Security_.authenticationLevel =
WbemAuthenticationLevelPktPrivacy
' =====================================================================
' Stop the spooler service.
' =====================================================================
Set colServices = objWMIService.ExecQuery("Select * from Win32_Service
where name = 'Spooler'")
errReturnCode = objService.StopService()
' =====================================================================
' Remove old printer.
' =====================================================================
rundll32 printui.dll, PrintUIEntry /gd /n\\cmw-file2\iR2800-fax
/c\\strComputer
' =====================================================================
' Start Spooler service.
' =====================================================================
errReturnCode = objService.StartService()
' =====================================================================
' End of your code.
' =====================================================================
Loop
Wscript.Echo "Done!"
objTextFile.Close
Line 39 is the rundll32 printui.dll, PrintUIEntry /gd
/n\\cmw-file2\iR2800-fax /c\\strComputer line and charactor 45 is right
between the \\ at /n\\cmw-file2\.
Question is, what is the syntax error with this line? I copied it right
out
of another command file I used to remove the printer manually and it
worked
fine there.
Any suggestions?
Thanks in advance,
Linn
Unlike batch procedures, WSH does not automatically have access to
the command line execution environment. Rather, the WScript.Shell
object's Run method must be invoked to 'shell' out to that
environment, something like this ...
sCmd = "rundll32 printui.dll, PrintUIEntry /gd " _
& "/n\\cmw-file2\iR2800-fax /c\\" & strComputer
with createobject("WScript.Shell")
nRes = .run(sCmd, 0, true)
end with
if nRes = 0 then
wsh.echo "Operation was sucessful"
else
wsh.echo "Operation was NOT sucessful"
end if
Tom Lavedas
===========
Thanks for the tip Tom. I was just zeroing in on this solution myself, just
hadn't worked out the syntax.
It took some doing but using your suggestion I finally got it working. Here
it is if anyone is interested:
' =====================================================================
' remote_printer_cleanup_install.vbs
' =====================================================================
On Error Resume Next
Const ForReading = 1
Const WbemAuthenticationLevelPktPrivacy = 6
strUser = "Administrator"
strPassword = "domainadminpassword"
Dim sCmd(4)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(".\computers.txt", ForReading)
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
' =====================================================================
' Insert your code here
' =====================================================================
' =====================================================================
' Remove old printer, need to shell out the command.
' =====================================================================
sCmd(0) = "rundll32 printui.dll, PrintUIEntry /gd /n\\cmw-file2\iR2800
/c\\" & strComputer
sCmd(1) = "rundll32 printui.dll, PrintUIEntry /gd /n\\cmw-file2\iR2800-fax
/c\\" & strComputer
sCmd(2) = "rundll32 printui.dll, PrintUIEntry /ga /n\\cmw-file2\Office3
/c\\" & strComputer
sCmd(3) = "rundll32 printui.dll, PrintUIEntry /ga
/n\\cmw-file2\Office3-fax /c\\" & strComputer
for i = 0 to 3
with createobject("WScript.Shell")
nRes = .run(sCmd(i), 0, true)
end with
if nRes = 0 then
' wsh.echo "Operation was sucessful"
else
wsh.echo "Operation was NOT sucessful on " & strComputer
end if
wScript.Sleep 1000
Next
' =====================================================================
' Stop the spooler service.
' =====================================================================
Set objWMIService = objwbemLocator.ConnectServer (strComputer,
strNamespace, strUser, strPassword)
objWMIService.Security_.authenticationLevel =
WbemAuthenticationLevelPktPrivacy
Set colServices = objWMIService.ExecQuery("Select * from Win32_Service
where name = 'Spooler'")
For Each objService in colServices
errReturnCode = objService.StopService()
wScript.Sleep 3000
' =====================================================================
' Start Spooler service.
' =====================================================================
errReturnCode = objService.StartService()
Next
' =====================================================================
' End of your code.
' =====================================================================
wsh.echo strComputer & " Complete!"
Loop
Wscript.Echo "Done!"
objTextFile.Close
I wanted to remove two printers and install two new ones so I decided to use
an array. I threw the sleep modes in there just to make sure processes had
time to complete. Hopefully someone will find this useful in the future.
:0)
Thanks again,
Linn
.
- References:
- WSH error help
- From: Linn Kubler
- Re: WSH error help
- From: Tom Lavedas
- WSH error help
- Prev by Date: unspecified error
- Next by Date: Re: Export Group Members
- Previous by thread: Re: WSH error help
- Next by thread: grant additional accounts the write members property
- Index(es):
Relevant Pages
|
Loading