Code: Select all
OnExit, ExitSub
return
ExitSub:
ahk_exe := StrSplit(A_AhkPath, "\")
ahk_exe := ahk_exe[ahk_exe.MaxIndex()]
query := "Select * from Win32_Process where Name = '" . ahk_exe . "'"
; MsgBox % query
for objItem in ComObjGet("winmgmts:").ExecQuery(query)
{
path := """" . A_ScriptFullPath . """"
is_path := InStr(objItem.CommandLine, path)
if (is_path) {
; WinKill, % "ahk_pid " . objItem.ProcessId
Process, Close, % objItem.ProcessId
}
; MsgBox % "path: " . path . "`r`ncmdline: " . objItem.CommandLine . "`r`nis_path: " . is_path
}
Code: Select all
OnExit, ExitSub
return
ExitSub:
ahk_exe := StrSplit(A_AhkPath, "\")
for objItem in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where Name = '" . ahk_exe[ahk_exe.MaxIndex()] . "'")
{
if (InStr(objItem.CommandLine, """" . A_ScriptFullPath . """")) {
Process, Close, % objItem.ProcessId
}
}