Been writing a script for showing and logging acceptance of a End User License Agreement for use over Active directory. It's written into a .hta file and uses VBScript for the most part.
I've run into a lot of issues that I have fixed so far but this last one has got me stumped.
When the file is run it gives me an
"End of Statement Expected"
error for line 35 of the script which is:
27 For Each ln in dict.Items
28 If ln = UserName Then
29 wasFound = true
30 End If
31 Next
32 If wasFound Then
33 WScript.Quit()
34 Else
35 Call DisableTaskMgr
36 Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
37 Set colItems = objWMIService.ExecQuery(wmiQuery)
38 For Each objItem in colItems
39 objItem.terminate(1)
40 Next
41 End If
I have no idea what it's asking me to change.
The full file can be found here
'On Error Resume Next
Set objShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
System = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\"
dim currentDir : currentDir = objShell.CurrentDirectory
UserName = objShell.ExpandEnvironmentStrings("%USERNAME%")
pathToDirectory = currentDir & "/store/directory.txt"
wasFound = false
row = 0
Version = "V1.0"
Set dict = CreateObject("Scripting.Dictionary")
Set directoryfile = fso.OpentextFile(pathToDirectory, 1)
dim strComputer : strComputer = "."
dim wmiNS : wmiNS = "/root/cimv2"
dim wmiQuery : wmiQuery = "Select processID from win32_process where name = 'explorer.exe'"
dim objWMIService
dim colItems
dim objItem
dim strOUT
Do Until directoryfile.AtEndOfStream
line = directoryfile.Readline
dict.Add row, line
row = row + 1
Loop
directoryfile.Close
For Each ln in dict.Items
If ln = UserName Then
wasFound = true
End If
Next
If wasFound Then
window.close
Else
Call DisableTaskMgr
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)
For Each objItem in colItems
objItem.terminate(1)
Next
End If
sub DisableTaskMgr
objShell.RegWrite System, "REG_SZ"
objShell.RegWrite System & "/DisableTaskMgr", 1, "REG_DWORD"
end sub
sub EnableTaskMgr
objShell.RegWrite System, "REG_SZ"
objShell.RegWrite System & "/DisableTaskMgr", 0, "REG_DWORD"
end sub
sub RestartExplorerExe
objShell.Run "explorer.exe"
end sub
sub Logon
Call EnableTaskMgr
If Not (fso.FileExists(currentDir & "/store/" & LCase(UserName) & ".csv")) Then
Set objFile = fso.CreateTextFile(currentDir & "/store/" & LCase(UserName) & ".csv", 2, True)
objFile.close
Else
End If
Set ObjOpenFile = fso.OpenTextFile(currentDir & "/store/" & UserName & ".csv", 8, -2)
objOpenFile.WriteLine(UserName & "," & Now & "," & Version)
objOpenFile.Close
Set objOpenFile = fso.OpenTextFile(currentDir & "/store/directory.txt", 8, -2)
objOpenFile.WriteLine(UserName)
objOpenFile.Close
Call RestartExplorerExe
window.close
end sub
sub Logoff
objShell.Run "shutdown /l"
end sub
If you guys find any other silly errors in the code I'd appreciate the help with those too, been working on this script for about 3 months.
EDIT: Most issues have now been fixed but I have run into a very odd issue that wasn't appearing before. Inside the CSV file that is created into the Logon method it is supposed to write {username},{date},{version number} but instead it writes random asian characters into the file.
On Error Resume Next
was causing my errors to be hidden. This was causing my inability to fix the script.
Taking that away gave me all the information I needed to fix all issues.