views:

603

answers:

3

I'm having trouble creating a small AutoHotkey script to end all vsjitdebugger.exe processes on a test server. Here's the code I have:

Process, Exist, vsjitdebugger.exe
NewPID = %ErrorLevel%
if NewPID = 0
{
    MsgBox Process doesnt exist
}
else
{
    MsgBox Process exists
}


Process, WaitClose, vsjitdebugger.exe, 5
NewPID = %ErrorLevel%
if NewPID = 0
{
    MsgBox Process no longer exists
}
else
{
    MsgBox Process still exists
}

When run the script tells me that the (vsjitdebugger.exe) process exists, as I would expect, but when WaitClose happens it still tells me that process(es) exist, and when I look in the Task Manager the same amount of vsjitdebugger.exe processes are still running.

I am able to end the vsjitdebugger.exe processes manually using Task Manager.

Basically I am unable to end these processes. Could anyone help me with this? Thanks.

Update: I've also tried this simple loop too, but with no avail:

Loop, 100
{
    Process, Close, vsjitdebugger.exe
}

Update 2: I tried the following code suggested below, but it just stays in the loop forever and no processes are killed:

Loop
{
    Process, Close, vsjitdebugger.exe
    Process, wait, vsjitdebugger.exe, 0.1             
    NewPID = %ErrorLevel%
    if NewPID = 0
    {
        break
    }   
}
+2  A: 

I do not have Microsoft Visual Studio installed on my computer, so I could not test using the exact process. I used notepad.exe instead. Using the simple loop you posted, I was able to successfully close 10 instances of notepad.

The following code worked on my computer (WinXP SP3) to close all instances of notepad.exe

Process, Exist, notepad.exe
NewPID = %ErrorLevel%
if NewPID = 0
{
    MsgBox, Process doesnt exist
}
else
{
    MsgBox, Process exists
}

Loop
{
    Process, Close, Notepad.exe
    Process, wait, Notepad.exe, 0.1  
    NewPID = %ErrorLevel%
    if NewPID = 0
    {
     break
    } 
}
Process, WaitClose, Notepad.exe
MsgBox, this works

I am not sure if this may be the cause of the any of the issues, but the WaitClose command does not close the process, it only waits for the process to no longer exist.

the3seashells
Thanks. See my update 2 above
Matthew Lock
+1  A: 

Assuming that you have a system with taskkill.exe on it (I know Windows XP does, and I believe all versions after that do too), you can use this line:

Run, %comspec% /c "taskkill /F /IM vsjitdebugger /T"
Agent_9191
Great that worked. I wonder why Process, Close doesn't work but calling taskkill does?
Matthew Lock
It's probably related to the forceful killing of the process or killing of the tree of processes that were spawned by it. That's what the /F and /T flags were for.
Agent_9191
+1  A: 

I just upgraded to Windows 7 and found I had the same problem with not being able to close a process. What worked for me was running the program in XP compatibility mode.

Korrigan