我运行到一个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 –