我運行到一個exe文件進行通信在Windows 7 的VBScript當PC處於鎖定狀態
一個VBScript VBScript的偉大工程,沒有工作!
我遇到的問題是,一旦PC被鎖定,進入睡眠或休眠狀態,VBScript就不會與exe應用程序通信。
VBScript的運行(我有一個日誌,告訴我每一次循環完成,但它不是通信exe文件。
下面是當PC被鎖定不工作的代碼。
Set WSHShell = WScript.CreateObject("WScript.Shell")
' info for exporting data
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, MyFile, FileName, TextLine, cycles
Dim I
I = 0
Dim n
n = .1 'how often the program saves the data (in minutes)
cycles = 2 'how many times it will save
FileName = "C:\Users\Desktop\new.txt" 'location where the log file will save
Dim sl
sl = n * 60000 'change from seconds to ms for the sleep function
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the file for output
Set MyFile = fso.OpenTextFile(FileName, ForAppending, True, TristateTrue)
' Write to the file.
MyFile.WriteLine "Log file for recording data from Yokogawa MX100 (" & cycles
& " cycles)"
WSHShell.Run "MXStandardE.exe"
WScript.Sleep 1000
WSHShell.AppActivate "MXStandardE.exe"
WScript.Sleep 1000
Do while I < cycles
a = Now()
WScript.Sleep 1000
WSHShell.Run "MXStandardE.exe"
WScript.Sleep 1000
WSHShell.AppActivate "MXStandardE.exe"
WScript.Sleep 1000
WSHShell.SendKeys "%A"
WScript.Sleep 1000
WSHShell.SendKeys "{DOWN}"
WScript.Sleep 1000
WSHShell.SendKeys "{ENTER}"
I = I + 1
MyFile.Writeline I & " of " & cycles & " at " & a & " --time of each cycle is
" & n & " minutes"
WScript.Sleep sl 'when sl is used loop time is in minutes
Loop
MyFile.Close
MsgBox ("Script has completed")
當個人電腦進入睡眠模式或休眠狀態時,操作被暫停,因此在這種情況下腳本的操作將被中斷(否則電腦不會首先進入睡眠/休眠狀態)。不過,鎖定屏幕不應該具有相同的效果(除非計算機在被鎖定時立即進入睡眠模式)。 *你的腳本究竟是「溝通」的?當你的電腦被鎖定時,你怎麼知道這一點?你能展示更多的代碼嗎?您的問題中的代碼段沒有顯示任何應該通過鎖定屏幕來中斷的內容。 –
謝謝Ansgar,我編輯了我的原始問題並添加了完整的代碼。 「Alt,Down,Enter」功能用於保存來自DAQ的數據。當我檢查網絡時,我可以看到它沒有保存,但日誌正在寫入文本文件。如果我看到應用程序沒有保存,我可以去電腦解鎖,應用程序再次保存。再次感謝,-Verrell –