Re: WSH error help



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/
.



Relevant Pages

  • [HPADM] [SUMMARY] lpspooler Question
    ... You might want to restart the print spooler and use the "-v" option to ... printer script, so anything inside the script may have caused the error. ... and you are sending the data to the remote computer to send to the printer. ... If laser33 uses an HP JetDirect adapter card, ...
    (HP-UX-Admin)
  • Re: Delete Print Queue on NT4
    ... command line? ... Unfortunately I do not know if the XP script below will work for NT4, but there it is just in case ... Is it possible to stop and reset the print spooler with a script? ... @echo off & setlocal enableextensions ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: WSH error help
    ... 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 ... Set objWMIService = objwbemLocator.ConnectServer (strComputer, ... wsh.echo "Operation was NOT sucessful" ...
    (microsoft.public.windows.server.scripting)
  • WSH error help
    ... 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 ... errReturnCode = objService.StartService ...
    (microsoft.public.windows.server.scripting)
  • Re: Trying to run script to enable and restart service
    ... sc config spooler start= auto ... script under the recovery option in the services console - (when service ... fails, run this script), but it does not run... ... What makes you think that the service sets itself to "disabled"? ...
    (microsoft.public.win2000.general)