2

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

到目前为止,我遇到了很多我已经解决的问题,但最后一个让我很难过。

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

“预期语句结束”

脚本第 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

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

完整的文件可以在这里找到

'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 个月。

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

4

1 回答 1

1

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

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

于 2016-01-29T11:11:31.167 回答