最近剛好有這個功能需求,找遍相關網路相關資料,原以為無解了,居然還是被我找到!
真的是「山重水複疑無路,柳暗花明又一村」
https://www.experts-exchange.com/questions/24218998/Check-if-a-process-is-running-in-vbs.html
rdpre.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "run.bat", 0, True
WshShell.AppActivate "mstsc"
strcomputer = "."
strProcess = "mstsc.exe"
check1()
WScript.Sleep 2000
check1()
If check1 = True then
check2()
End if
WshShell.SendKeys "q"
WshShell.SendKeys "exit+{ENTER}"
WScript.Sleep 60000
WshShell.run "shutdown.exe -L -F"
function check1()
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process where name = 'mstsc.exe'")
For Each objProcess in colProcessList
if objProcess.Name = strProcess Then
check1 = True
Else
check1 = false
End If
Next
i = 1
End function
sub check2()
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancedeletionevent " _
& "within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
Set objLatestProcess = colMonitoredProcesses.NextEvent
if objLatestProcess.TargetInstance.Name = strProcess Then
Exit Do
End if
Loop
End sub
run.bat
@echo off
start record.bat
c:
%windir%\system32\mstsc.exe
https://sourceforge.net/projects/screencapturer/files/
record.bat
@echo off
set /a date=%date:~0,4%%date:~5,2%%date:~8,2%
set /a time=%time:~0,2%%time:~3,2%
c:
cd C:\Program Files (x86)\Screen Capturer Recorder\configuration_setup_utility\vendor\ffmpeg\bin
ffmpeg.exe -f dshow -i video=screen-capture-recorder d:\records\%date%%time%.mp4
訂閱:
張貼留言 (Atom)
0 意見:
張貼留言