Re: WSH error help
- From: Tom Lavedas <tglbatch@xxxxxxx>
- Date: Tue, 8 Apr 2008 11:04:35 -0700 (PDT)
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
===========
http://members.cox.net/tglbatch/wsh/
.
- Follow-Ups:
- Re: WSH error help
- From: Linn Kubler
- Re: WSH error help
- References:
- WSH error help
- From: Linn Kubler
- WSH error help
- Prev by Date: Re: Export Group Members
- Next by Date: grant additional accounts the write members property
- Previous by thread: WSH error help
- Next by thread: Re: WSH error help
- Index(es):
Relevant Pages
|