"End of Statement Expected" 在 VBScript 文件中

"End of Statement Expected" in VBScript file

正在编写一个脚本,用于显示和记录对最终用户许可协议的接受,以便在 Active Directory 上使用。它被写入一个 .hta 文件并且大部分使用 VBScript。

到目前为止,我已经 运行 解决了很多问题,但最后一个问题让我很困惑。

当文件为 运行 时,它给了我一个

"End of Statement Expected"

脚本第 35 行错误,即:

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

我不知道它要求我更改什么。

可以找到完整的文件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

如果你们在代码中发现任何其他愚蠢的错误,我也会感谢您的帮助,我已经为此脚本工作了大约 3 个月。

编辑:现在大多数问题都已解决,但我 运行 遇到了一个以前没有出现过的非常奇怪的问题。在登录方法中创建的 CSV 文件中,它应该写入 {username},{date},{version number} 但它却将随机亚洲字符写入文件。

On Error Resume Next 导致我的错误被隐藏。这导致我无法修复脚本。

把它拿走给了我解决所有问题所需的所有信息。