Force-quit a Shell (Windows)

@Andrew Lambert - that doesn’t work for 64 bit OS, right?

It works on 32 and 64 bit Windows. However, it seems that Shell.PID doesn’t actually return a PID on Windows, so you’ll have to get the ID number someplace else (look at the Windows Functionality Suite’s process handling code for examples of finding a process ID.)

That’s odd, I do seem to get a valid PID from the shell instance. I’m on Windows 7x64, Xojo 2013r3.3.

I don’t, using the same OS and IDE version. I get a number that doesn’t correspond to any running process or thread ID. screenshot.

Correction: I’m using Xojo 3.2. Updating now.

Just tried 3.3, same behavior. I made this feedback case so as not to hijack @Doug Craig’ thread: <https://xojo.com/issue/30771>

Andrew,

you get the process handle not the process ID (PID).
The property name is very confusing…

[quote=45968:@Maurizio Rossi]Andrew,

you get the process handle not the process ID (PID).
The property name is very confusing…[/quote]
What kind of process handle? Can I use it like a handle from OpenProcess?

Apparently I can!

Function KillShell(sh As Shell) As Integer
  Declare Function TerminateProcess Lib "Kernel32" (ProcessHandle As Integer, ExitCode As Integer) As Boolean
  Declare Function GetLastError Lib "Kernel32" () As Integer
  If TerminateProcess(sh.PID, 0) Then
    Return GetLastError()
  End If
End Function

Yes, exactly this way,
You can use the handle as a parameter to the GetProcessId() Win32 function to get the process ID (PID).