Autohotkey 如果安装了驱动器,请运行程序并退出
如果安装了X:\我将使用此脚本运行程序,如果不再安装X:\我将退出应用程序。我如何优化它Autohotkey 如果安装了驱动器,请运行程序并退出,autohotkey,Autohotkey,如果安装了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, RunTheScr
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
编辑:
如果只需要脚本卸载卷,请尝试以下操作:
#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
}
谢谢您。我应该提到“notepad”是一个卸载X:\,所以我不需要第二个if语句的程序。如何让X:\有足够的时间卸载以避免“记事本”无限期运行,并允许脚本退出?请尝试编辑后的答案(如果我理解正确)。
#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
}