Checking VBScript for syntax error
Checking VBScript for syntax error
I have a simple VBScript that copies a few files and calls a custom executable from the copied files on the system to set up a scheduled task. I am not well versed in VBScript and getting an error during compilation. It says "Expected end of statement".
Here is my script. PLease help me get rid of that compilation error.
Set objFso = CreateObject("Scripting.FileSystemObject")
Set wshshell = CreateObject("WScript.Shell")
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
ScriptPath = objfso.GetParentFolderName(WScript.ScriptFullName)
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
Set objRegistry = GetObject("winmgmts:" & strComputer &
"rootdefault:StdRegProv")
Set XMLDOM = CreateObject("Microsoft.XMLDOM")
XMLDOM.Async = False
logfile = WinDir & "CDFLogsJoinDom.log"
If
WScript.Arguments.Named.Exists("elevated") = False
Then
'Launch the script again as administrator
CreateObject("Shell.Application").ShellExecute "wscript.exe", """" &
WScript.ScriptFullName & """ /elevated", "", "runas", 1
WScript.Quit
Else
Set LogF = objfso.CreateTextFile(logfile)
End If
If Right(ScriptPath, 1) <> "" Then
ScriptPath = ScriptPath & ""
logF.WriteLine ("******************Script is running from " & ScriptPath)
End If
JoinDomOffline
Sub JoinDomOffline
objFso.CopyFile ScriptPath & "FilesJoinDomain.exe", "C:Windows"
objFso.CopyFile ScriptPath &
"FilesJoinDomain.xml","C:WindowsSystem32Tasks"
wshshell.Run cmd.exe /c schtasks /Create /TN "JoinDomain" /XML
"C:WindowsSystem32TasksJoinDOmain.xml"
End Sub
WScript.Quit
I see 3 major issues with your code. a) The
Else
is missing an End If
. b) If you want to continue a statement in the next line you MUST put an underscore at the end of the line. Ending a line with the concatenation operator is NOT sufficient. c) The quoting in your wshshell.Run
line is broken.– Ansgar Wiechers
Jun 29 at 23:13
Else
End If
wshshell.Run
Edited based on the above comments..still does not seem to resolve
– Alcox
Jun 29 at 23:45
can you post the correct script here...i am sure it would take long for experienced guys like you
– Alcox
Jun 29 at 23:46
You're clearly not listening. You have a glaring, very clear missing
End
after your edit. Are you reading the code? And your indentation is still wrong. Outdent the Sub JoinDomOffLine
and it's code to the margin. See the large hole in the middle between the Else
and that new Sub
location? Figure out what's missing in that area.– Ken White
Jun 29 at 23:53
End
Sub JoinDomOffLine
Else
Sub
1 Answer
1
You are missing an End statement. Every IF / ELSE / END block needs to be closed. A quick scan of the script and I am assuming it is after the Set LogF = objfso.CreateTextFile(logfile) statement.
Editors like Notepad++ or Visual Studio highlight these problems. It is easy to miss them in a text editor with code that is not indented.
can you post the correct script here...i am sure it would take long for experienced guys like you
– Alcox
Jun 29 at 23:46
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Learn to properly indent your code, and you'll be able to figure these sorts of problems out for yourself.
– Ken White
Jun 29 at 22:57