如果安装了X:\,我正在使用此脚本运行程序,而当不再安装X:\时,我将退出应用程序。我该如何优化呢?
DriveGet, status, Status, X:\
if (status = "Ready")
Run ~
SetTimer, RunTheScript, 500
return
RunTheScript:
DriveGet, status, Status, X:\
if (status = "Ready")
return
; Otherwise:
SetTimer, RunTheScript, off
ExitApp
答案 0 :(得分:1)
#Persistent ; keeps the script permanently running
SetTimer, RunCloseProgram, 500
return
RunCloseProgram:
If (FileExist("X:\") && (!ProcessExist("notepad.exe"))) ; "&&" means "AND" and "!" means "NOT"
Run notepad
If (!FileExist("X:\") && (ProcessExist("notepad.exe")))
Process Close, notepad.exe
return
ProcessExist(name){
Process, Exist, %name%
return Errorlevel
}
编辑: 如果只需要脚本来卸载卷,请尝试以下操作:
#Persistent
If !(FileExist("X:\"))
{
MsgBox, "X:\" doesn't exist
ExitApp
}
; Otherwise:
If (!ProcessExist("program.exe"))
Run path of the program.exe
Process, wait, program.exe
Sleep, 10000
SetTimer, CloseProgram, 500
return
CloseProgram:
If (!FileExist("X:\"))
{
SetTimer, CloseProgram, off
Sleep, 10000 ; or more (allow sufficient time for X:\ to dismount)
Process Close, program.exe
ExitApp
}
return
ProcessExist(name){
Process, Exist, %name%
return Errorlevel
}