我正在寻找一个批处理文件,它会在打开程序后的某个时间关闭程序。因此,例如,如果我打开我的电子邮件程序,将触发批处理文件,两分钟后,我的电子邮件将自动关闭。如果可能的话,我还希望命令窗口打开隐藏。我尝试使用事件记录器和任务计划程序,但我无处可去 有什么建议吗? 谢谢!
答案 0 :(得分:0)
运行命令隐藏
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /k dir c:\windows\*.*", 0, false
这会检测应用何时退出。在记事本退出时,它会重新启动它。您可以将其更改为处理启动,停止或两者。 Win32_ProcessStopTrace
,Win32_ProcessStartTrace
和Win32_ProcessStartStopTrace
。
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set objEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM Win32_ProcessStopTrace")
Do
Set objReceivedEvent = objEvents.NextEvent
msgbox objReceivedEvent.ProcessName
If lcase(objReceivedEvent.ProcessName) = lcase("Notepad.exe") then
Msgbox "Process exited with exit code " & objReceivedEvent.ExitStatus
WshShell.Run "c:\Windows\notepad.exe", 1, false
End If
Loop
这会查看正在运行的进程列表以及Calculator是否终止它。
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
For Each objItem in colItems
'msgbox objItem.ProcessID & " " & objItem.CommandLine
If objItem.name = "Calculator.exe" then objItem.terminate
Next
让脚本等待。来自https://www.microsoft.com/en-au/download/details.aspx?id=2764的帮助
暂停脚本执行指定的时间长度,然后继续执行。
object.Sleep(intTime)
<强>对象强> WScript对象。
<强> intTime 强> 整数值,指示您希望脚本进程处于非活动状态的时间间隔(以毫秒为单位)。
所以wscript.sleep 120000
是两分钟
我会让你把它绑在一起。