Very Simple VBS script not working

gino angelozzi 1 Reputation point
2022-02-04T18:05:58.243+00:00

I keep getting an Expected Statement error typing to run the following script:

Create the objects and variables needed

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Check for an existing host ID

objFSO.FileExists("c:\Files\RCHostID.reg") Then

Host ID found, restore ID and enable service

strCMD = "regedit /s c:\Files\RCHostID.reg ""HKEY_USERS\S-1-5-18\Software\Dell SecureWorks"""
objShell.Run(strCmd)
strCMD = "sc config ""redcloak"" start= auto"
objShell.Run(strCmd)

Delay and then start service

WScript.Sleep 5000
strCMD = "sc start ""redcloak"""
objShell.Run(strCmd)

Clear objects

Set objShell = Nothing
Set objFSO = Nothing

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
866 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 47,966 Reputation points
    2022-02-04T18:33:26.553+00:00

    Just based upon your posted blocks of code it doesn't look like valid VBS to me. Besides the lack of set statements that are generally needed you have what looks like an if statement for the file exists but you have no if, just the then. Please post the entire script as is so we can confirm the actual problem.

    0 comments No comments

  2. gino angelozzi 1 Reputation point
    2022-02-04T19:09:09.33+00:00

    Create the objects and variables needed

    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Check for an existing host ID

    objFSO.FileExists("c:\Files\RCHostID.reg") Then

    Host ID found, restore ID and enable service

    strCMD = "regedit /s c:\Files\RCHostID.reg ""HKEY_USERS\S-1-5-18\Software\Dell SecureWorks"""
    objShell.Run(strCmd)
    strCMD = "sc config ""redcloak"" start= auto"
    objShell.Run(strCmd)

    Delay and then start service

    WScript.Sleep 5000
    strCMD = "sc start ""redcloak"""
    objShell.Run(strCmd)

    Clear objects

    Set objShell = Nothing
    Set objFSO = Nothing