Click here to Skip to main content
15,884,298 members
Home / Discussions / C#
   

C#

 
GeneralRe: socket timeout Pin
Rüpel23-Sep-02 10:09
Rüpel23-Sep-02 10:09 
Generalstill doesn't work Pin
Rüpel23-Sep-02 20:52
Rüpel23-Sep-02 20:52 
Generalfinally Pin
Rüpel23-Sep-02 21:53
Rüpel23-Sep-02 21:53 
GeneralEiffel .NET for Visual Studio .NET Plug-in Pin
Kevin McFarlane20-Sep-02 1:50
Kevin McFarlane20-Sep-02 1:50 
GeneralBackground and foreground color for disabled state Pin
valos20-Sep-02 1:18
valos20-Sep-02 1:18 
QuestionShut down one program from another? Pin
Matt Philmon19-Sep-02 18:11
Matt Philmon19-Sep-02 18:11 
AnswerRe: Shut down one program from another? Pin
Stephane Rodriguez.19-Sep-02 19:08
Stephane Rodriguez.19-Sep-02 19:08 
GeneralRe: Shut down one program from another? Pin
Matt Philmon19-Sep-02 20:50
Matt Philmon19-Sep-02 20:50 
Thanks for that... it drove me down a twisting road that led me to a somewhat interesting conclusion (which still leaves me unable to solve my problem).

First, the result: For some reason, a Windows Service written in .NET (well, at least I know it's true in VB.NET) seems unable to get the Window Handle for a window in another process. There's probably a reason I'm missing but... onto the evidence!

I took your stuff from above and ported over to VB.NET, wrote a small utility like normal (except I used WM_CLOSE instead of WM_QUIT - though it worked with both). The VB app was able to shut down (for this quick test, I was shutting down Notepad) Notepad every time. I also tried a mix of the two with success... I used my code to look up the processname "Notepad", then iterated through the collection and:
Dim wnd As System.IntPtr<br />
wnd = Process.MainWindowHandle<br />
hWnd = wnd.ToInt32<br />
If hWnd <> 0 Then<br />
    Call SendMessage(hWnd, WM_CLOSE, 0, 0)<br />
End If
This also worked great (just another way other than FindWindow to get the Window Handle).

So I took that code and wrote a quick and dirty window service. Using FindWindow exactly the same way, FindWindow could not get a window handle. Using my method, I was able to get at the process without trouble by looking by process name. However, even though I did get to the Notepad process without trouble which I verified in the debugger, my call to MainWindowHandle() ALSO gave me a NULL. So, what I found out is that BOTH methods failed to get a window handle.... and I bet if we take apart the code to CloseMainWindow like you did above for Kill and WaitforExit we'll find they are using the Window Handle which is why I can't make this work in a service.

Now, why in the world would I be unable to get the Window Handle of a process I can see just fine (and even Kill()) inside a Windows Service!!!??!? Is this a .NET bug?
GeneralRe: Shut down one program from another? Pin
Stephane Rodriguez.19-Sep-02 21:23
Stephane Rodriguez.19-Sep-02 21:23 
GeneralRe: Shut down one program from another? Pin
Matt Philmon20-Sep-02 4:47
Matt Philmon20-Sep-02 4:47 
GeneralRe: Shut down one program from another? Pin
leppie20-Sep-02 5:22
leppie20-Sep-02 5:22 
GeneralRe: Shut down one program from another? Pin
Matt Philmon20-Sep-02 21:33
Matt Philmon20-Sep-02 21:33 
GeneralRe: Shut down one program from another? Pin
Stephane Rodriguez.21-Sep-02 1:52
Stephane Rodriguez.21-Sep-02 1:52 
GeneralRe: Shut down one program from another? Pin
leppie21-Sep-02 2:01
leppie21-Sep-02 2:01 
GeneralRe: Shut down one program from another? Pin
Matt Philmon21-Sep-02 5:49
Matt Philmon21-Sep-02 5:49 
GeneralBeta of .NET Framework Version 1.1 now available Pin
Eric Gunnerson (msft)19-Sep-02 12:30
Eric Gunnerson (msft)19-Sep-02 12:30 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone19-Sep-02 13:11
sitebuilderDavid Stone19-Sep-02 13:11 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Eric Gunnerson (msft)23-Sep-02 7:30
Eric Gunnerson (msft)23-Sep-02 7:30 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Matt Philmon20-Sep-02 21:34
Matt Philmon20-Sep-02 21:34 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
James T. Johnson21-Sep-02 2:07
James T. Johnson21-Sep-02 2:07 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
leppie21-Sep-02 2:06
leppie21-Sep-02 2:06 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone21-Sep-02 5:26
sitebuilderDavid Stone21-Sep-02 5:26 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
leppie21-Sep-02 5:50
leppie21-Sep-02 5:50 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone21-Sep-02 10:57
sitebuilderDavid Stone21-Sep-02 10:57 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
leppie23-Sep-02 10:29
leppie23-Sep-02 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.