Re: Determining if a windows application is already running

Georg Ragaller <[email protected]>
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <LISTSERV%[email protected]>
Hi Jim!

In my posting 2 weeks ago (http://discuss.develop.com/archives/wa.exe?
A2=ind0504b&L=jawin&T=0&F=&S=&P=644) I described how to use
GetActiveObject from OLEAUT32.DLL to retrieve a pointer to a
running (and registered) COM instance.

With the sample code from my second posting

(remove the
...
            Ole32.CoCreateInstance
(clsid,Ole32.CLSCTX_ALL,WellKnownGUIDs.IID_IUnknown);

            System.out.println(clsid);
            System.out.flush();
...  :)

you can use something like

...
public static final int MK_E_UNAVAILABLE   = 0x800401E3;
...

IUnknown unknown = null;

try
{
    unknown = OleAut32.GetActiveObject("Application.Word");
}
catch (COMException ex)
{
    if (MK_E_UNAVAILABLE != ex.hresult)
    {
       throw ex;
    }
}

boolen wordRunning = (null != unknown);
...



Georg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.