Re: Fails to terminate SystemInfo(msInfo32.exe) programatically

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



FindWindow() was just an example.

If your program is a general purpose launcher (and Msinfo32.exe was used only as an example?) you can try the following:

Enumerate all top level windows and call GetWindowThreadProcessId() for each. If the returned process id match the one returned by ShellExecuteEx/CreateProcess then you have the handle of the window you want to close. You can send WM_CLOSE now. (But notice that many applications may display some confirmation dialog before quiting, so if you are determined to close the app anyway you might have no choise but to use TerminateProcess() if after some timeout after sending WM_CLOSE an apllication is stiill there.)

Indu wrote:
Grzegorz , thanks for replying to my post.

The applications that needs to be launched is taken us an input from the user. If I have to use FindWindow call to terminate the applications then, we should know the title of the applications also. But, we can not mandate the user to provide the title along with the applications.

How should I resolve this issue. I have only the list of applications with their path as an input. I should launch and terminate them.


"Grzegorz Wróbel" wrote:

Indu wrote:
Hi,
MsInfo32.exe is a Microsoft application. I am launching it from my application using ShellExcecuteEx API. This call just returns me an hProcess. I am using this handle to a process to terminate it , using TerminateProcess() API.

Other than hProcess, i have no other information about the process.

Using this approach I am successful in launching and terminating various other Microsoft applications like regedit.exe,Ntepad.exe, services.msc etc.
Indu, you should read the Remarks section in MSDN to find out why you shouldn't use TerminateProcess unless you really have too.

You can obtain HWND of MsInfo32.exe for example by calling FindWindow("PCHShell Window","System Information");

PS. GDI is not the right newsgroup for this question (I though I was reading it on comp.os.ms-windows.programmer.win32).

--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D



--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
.



Relevant Pages

  • Re: slow responses from XP...
    ... At the time of launching applications the system is idle ... and the only thing "using" the CPU is the system idle process. ...
    (microsoft.public.windowsxp.general)
  • Re: The Excellent Dock...
    ... only icons for currently active applications and icons for deliberately ... If I were to put all my applications in the dock it would ... then appear in the dock is the order in which you launched them. ... I switched from launching with Quicksilver to ...
    (comp.sys.mac.apps)
  • Getting menu handle from a floating menu bar
    ... I am launching many applications from my application in background. ... to get the menu pointer using CWnd::GetMenufrom the mainframe pointer. ... I get the handle of the docking menu bar window (This handle is the same I ...
    (microsoft.public.vc.mfc)
  • Re: Safari alias in dock
    ... I keep a "minimal" dock and use LaunchBar for launching applications. ... Removing the Safari icon ...
    (comp.sys.mac.system)
  • Re: Software Restriction Problem
    ... I have yet to see this stinkin' thing ... default OS junk and a select few applications... ... > launching. ...
    (microsoft.public.windows.group_policy)