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.
Very Simple VBS script not working

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
2 answers
Sort by: Most helpful
-
Michael Taylor 41,626 Reputation points
2022-02-04T18:33:26.553+00:00 -
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