# Force-quit a Shell (Windows)

**URL:** <https://forum.xojo.com/t/force-quit-a-shell-windows/12099>\
**Category:** Windows\
**Created:** [November 4, 2013, 9:40pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099 "2013-11-04T21:40:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 4, 2013, 9:40pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/1 "2013-11-04T21:40:48Z")

</div>

Does anyone know how to force quit a Shell in Windows? Calling the Shell.Close method does not seem to accomplish this. RealStudio 2012 R1.1

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [November 4, 2013, 10:01pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/2 "2013-11-04T22:01:31Z")

</div>

What happens if you set the Shell to Nil?

---

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 4, 2013, 10:24pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/3 "2013-11-04T22:24:50Z")

</div>

Brilliant. Thanks, Paul. Don’t know why I didn’t think of that before! sigh! haha.

---

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 7, 2013, 6:40pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/4 "2013-11-07T18:40:05Z")

</div>

Actually, no, that’s not working at all. I’m totally stumped at this point.

---

<div class="post-metadata">

**Author:** ![Tim\_Jones](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_jones/32/8627_2.png) [@Tim\_Jones](https://forum.xojo.com/u/Tim_Jones)\
**Post date:** [November 7, 2013, 7:00pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/5 "2013-11-07T19:00:58Z")

</div>

Try sending a ChrB(3) to the shell. I suspect that you have a long running app that you started in the shell that’s holding it open.

---

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 8, 2013, 5:29pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/6 "2013-11-08T17:29:11Z")

</div>

Still doesn’t seem to work.

What I’ve got is a print control that spawns a thread that has a shell, the thread executes the shell (in this case, calling the printhtml.exe utility to print an html document to a printer), but the shell never closes/quits even after successfully printing the document. So when the program quits, there’s still a ton of cmd.exe and printhtml.exe’s still running in the processes.

---

<div class="post-metadata">

**Author:** ![Tim\_Jones](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_jones/32/8627_2.png) [@Tim\_Jones](https://forum.xojo.com/u/Tim_Jones)\
**Post date:** [November 8, 2013, 5:48pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/7 "2013-11-08T17:48:19Z")

</div>

What if you send an “exit” as part of the shell.execute:

```auto
theShell.Execute "printhtml.exe " + args + " & exit"
```

---

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 8, 2013, 6:03pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/8 "2013-11-08T18:03:34Z")

</div>

Still nothing. Here’s the shell command

“C:\Users\dougc\Documents\RealBasic Projects\labnet2\DebugLabNet201x\resources\printhtml.exe” file=“C:\Users\dougc\AppData\Local\Temp\00000001891870988196.tmp” printername=“ZDesigner LP 2844” & exit

and it’s just hanging in the task manager processes. The document printed fine.

---

<div class="post-metadata">

**Author:** ![Tim\_Jones](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_jones/32/8627_2.png) [@Tim\_Jones](https://forum.xojo.com/u/Tim_Jones)\
**Post date:** [November 8, 2013, 6:05pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/9 "2013-11-08T18:05:56Z")

</div>

Now this is sounding like a bug. I had seen something like this many revisions ago, but I thought that it had been fixed.

I recommend that you submit a feedback report on this issue.

---

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 8, 2013, 6:06pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/10 "2013-11-08T18:06:50Z")

</div>

In the meantime, how would I get around it? Force-quit the PID of anything matching “printhtml.exe”?

---

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 8, 2013, 6:10pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/11 "2013-11-08T18:10:55Z")

</div>

I checked out the process in the resource monitor for the multipe printhtml.exe instances and they all indicated they were waiting for Splwow64.exe in the wait-chain.

This might be it… [http://support.microsoft.com/kb/2815716](http://support.microsoft.com/kb/2815716)

“Splwow64.exe process doesn’t end after a print job finishes in the 64-bit version of Windows 7”

---

<div class="post-metadata">

**Author:** ![Tim\_Jones](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_jones/32/8627_2.png) [@Tim\_Jones](https://forum.xojo.com/u/Tim_Jones)\
**Post date:** [November 8, 2013, 6:12pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/12 "2013-11-08T18:12:20Z")

</div>

That would definitely explain what you’re seeing. Until all of the bits of the chain exit, the shell is effectively still running. Scrub creating a feedback report…

---

<div class="post-metadata">

**Author:** ![Tim\_Jones](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_jones/32/8627_2.png) [@Tim\_Jones](https://forum.xojo.com/u/Tim_Jones)\
**Post date:** [November 8, 2013, 6:13pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/13 "2013-11-08T18:13:49Z")

</div>

At least MS has a hot fix available…

---

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 8, 2013, 6:17pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/14 "2013-11-08T18:17:30Z")

</div>

I’m going to install any updates as of today, restart, try again, and if still failure, then try the hotfix, and report back.

---

<div class="post-metadata">

**Author:** ![Doug\_Craig](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@Doug\_Craig](https://forum.xojo.com/u/Doug_Craig)\
**Post date:** [November 8, 2013, 6:55pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/15 "2013-11-08T18:55:00Z")

</div>

Unfortunately neither worked, and I am discovering a multitude of users via google that also have problems with this.

The only solution I can see is to force quit the applications… would you happen to know where to point me as to how to figure out what the PID of the processes are and force-quit them problematically?

---

<div class="post-metadata">

**Author:** ![Tim\_Jones](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_jones/32/8627_2.png) [@Tim\_Jones](https://forum.xojo.com/u/Tim_Jones)\
**Post date:** [November 8, 2013, 10:40pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/16 "2013-11-08T22:40:55Z")

</div>

Even the hotfix didn’t resolve this?

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 8, 2013, 10:53pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/17 "2013-11-08T22:53:23Z")

</div>

> [@44856:@Doug Craig](#):
>
> In the meantime, how would I get around it? Force-quit the PID of anything matching “printhtml.exe”?

Quick and dirty hunch : call your shell from a threaded batch script. Then the batch script would be the owner of the processes, right ?

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [November 8, 2013, 11:17pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/18 "2013-11-08T23:17:10Z")

</div>

> [@44867:@Doug Craig](#):
>
> The only solution I can see is to force quit the applications… would you happen to know where to point me as to how to figure out what the PID of the processes are and force-quit them problematically?

Pass the `Shell.PID` property to this method (Win32 only):

```auto
Function KillProcess(ProcessID As Integer, ExitCode As Integer = 0) As Integer
  Declare Function OpenProcess Lib "Kernel32" (DesiredAccess As Integer, InheritHandle As Boolean, ProcessId As Integer) As Integer
  Declare Function TerminateProcess Lib "Kernel32" (ProcessHandle As Integer, ExitCode As Integer) As Boolean
  Declare Function CloseHandle Lib "Kernel32" (Handle As Integer) As Boolean
  Declare Function GetLastError Lib "Kernel32" () As Integer
  Const PROCESS_TERMINATE = &h1
  
  Dim pHandle, lasterr As Integer
  pHandle = OpenProcess(PROCESS_TERMINATE, False, ProcessID)
  lasterr = GetLastError()
  
  If lasterr = 0 And TerminateProcess(pHandle, ExitCode) Then
     lasterr - GetLastError()
    Call CloseHandle(pHandle)
  End If
  
  Return lasterr
End Function
```

---

<div class="post-metadata">

**Author:** ![Jim\_Cramer](https://forum.xojo.com/user_avatar/forum.xojo.com/jim_cramer/32/2268_2.png) [@Jim\_Cramer](https://forum.xojo.com/u/Jim_Cramer)\
**Post date:** [November 8, 2013, 11:21pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/19 "2013-11-08T23:21:08Z")

</div>

Doug,

Did you try the following (from: [http://support.microsoft.com/kb/2815716](http://support.microsoft.com/kb/2815716)):

To Configure a timeout value for SPLWow64.exe

Click Start, and then click Run.  
Type regedit, and then click OK.  
Locate and then right-click the following registry subkey:  
HKEY\_LOCAL\_MACHINE\SYSTEM\CurrentControlSet\Control\Print  
Point to New, and then click DWORD Value.  
Type SplWOW64TimeOutSeconds as the registry entry name, and then press Enter.  
Double-click the SplWOW64TimeOutSeconds entry that you created in step 4.  
Enter a value in the Value data box, and then click OK.

IMO terminating the process would be a last resort option.

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [November 8, 2013, 11:23pm UTC](https://forum.xojo.com/t/force-quit-a-shell-windows/12099/20 "2013-11-08T23:23:00Z")

</div>

[quote=44910:@Andrew Lambert]

`
     lasterr - GetLastError()
 `[/quote]

Should be:

```auto
     lasterr = GetLastError()
```

[Next page](https://forum.xojo.com/t/force-quit-a-shell-windows/12099.md?page=2)
