每次我需要授予用户对我们服务器上文件共享的访问权限时,我都会多次出现此弹出窗口,因为该过程会遇到我无法修改其访问权限的各种文件:
这不是问题,但我厌倦了不得不反复停止我正在处理的工作以单击“继续”按钮。因此,我编写了一个程序来不断地扫描“应用安全性错误”窗口,并在找到时向其发送“Enter”键。这工作得很好,但由于中央循环永远不会终止,我决定添加在程序完成时结束程序的能力。我本可以使用 .hta 文件,但我决定尝试一种不同的方法,将所有内容保存在一个文件中,以使将来的维护更容易。我采用了这个 Stack Overflow 问题中的代码来查找我的程序的 PID,并允许在关闭弹出窗口后使用 Windows TASKKILL 命令结束程序。
该程序似乎可以正常工作,识别其 PID 并将其传递给弹出窗口。但是,当 TASKKILL 运行时,它声称 PID 不存在。谁能看到我做错了什么?提前感谢所有回复的人。
' AutoContinue.vbs
' Program to automatically close all "Error Applying Security" messages
Option Explicit
Const Hidden = 0
Dim objWshShell, objWMILocator, objWMIService
Dim strComputerName, objArgs, objChildProcess, colPIDs, objPID
Set objWshShell = CreateObject( "WScript.Shell" )
Set objWMILocator = CreateObject( "WBemScripting.SWbemLocator" )
Set objWMIService = objWMILocator.ConnectServer( "", "", "", "" )
Function MyProcessID ()
' MyProcessID finds and returns my own PID.
MyProcessID = 0
Set objChildProcess = objWshShell.Exec( "%comspec% /C pause" )
Set colPIDs= objWMIService.ExecQuery( "Select * From Win32_Process" & _
" Where ProcessId=" & objChildProcess.ProcessID,, 0 )
For Each objPID In colPIDs
MyProcessID = objPID.ParentProcessID
Next
Call objChildProcess.Terminate()
End Function
Set objArgs = WScript.Arguments
If objArgs.Count = 1 Then
If objArgs.Item(0) = "Popup" Then
objWshShell.Popup( "AutoContinue PID is " & MyProcessID & _
vbCrLf & "Hit OK when done." )
' objWshShell.Run "taskkill /PID " & MyProcessID & " /T", 1
objWshShell.Run "%comspec% /k taskkill /PID " & MyProcessID & " /T", 1
Set objArgs = Nothing
Set objWshShell = Nothing
WScript.Quit
End If
End If
objWshShell.Run "wscript.exe " & WScript.ScriptName & " Popup", Hidden
Do
Do
WScript.Sleep( 500 )
Loop While Not objWshShell.AppActivate( "Error Applying Security" )
WScript.Sleep( 100 )
objWshShell.AppActivate( "Error Applying Security" )
WScript.Sleep( 100 )
objWshShell.SendKeys( "{ENTER}" )
Loop While True
Set objWshShell = Nothing