Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SYNCHRONIZE access is only for NT/2000? 1

Status
Not open for further replies.

apatterno

Programmer
Nov 26, 2002
368
US
I have obtained a Process Identifier that I intend to use in a wait function. I understand that I must use OpenProcess to get a handle to the process. The first parameter of OpenProcess specifies the desired access to the handle... I think I need to specify [tt]SYNCHRONIZE[/tt] access, but the SDK documentation says that's for NT/2000 only.

Is it not possible to wait on process handles under 9x/ME?

And if so, how do I request the proper access rights?

Thanks for all the help you have to give, in advance.
 
>> Is it not possible to wait on process handles under 9x/ME?

Not unless your process created the process.

-pete
 
Thank you.

I should probably say exactly what I want to do:

There is a program (Winamp, specifically) that I want to shut down (via a WM_CLOSE) and then I want to wait until the process has actually exited.

(More specifically, I want to wait until it has written its settings to the INI file.)

My logic works as follows:

[tt]HWND hwndWinamp;
DWORD dwWinampPID;
HANDLE hProcessWinamp;

hwndWinamp = FindWindow("Winamp v1.x",NULL);
if (hwndWinamp != NULL) {
GetWindowThreadProcessId(hwndWinamp, &dwWinampPID);

// close Winamp's window
SendMessage(hwndWinamp, WM_CLOSE, 0,0);

// wait for the process to REALLY exit.
hProcessWinamp = OpenProcess(SYNCHRONIZE,FALSE,dwWinampPID);
WaitForSingleObject(hProcessWinamp, INFINITE);
}[/tt]

And you can't do that under 9x/ME?

Is there any workaround or other way to do it?
 
There is not a equal way to do it but you could simply post the WM_CLOSE and then use Sleep() or a Timer until IsWindow() returns false.

It's a hack but maybe it works for you, dunno

-pete
 
Thank you again.

My concern was that the user might have "fade-outs" enabled, which could the process running for a few seconds after the window is closed.

I am going to try something where I repeatedly call OpenProcess / CloseHandle, until the OpenProcess call fails (indicating that Winamp's PID is no longer valid) -- I'll let you know in case anyone else is following this thread.

I REALLY hope that helps.
Will
 
Be aware that PID's are reused by the OS so there is no guarantee that by the time you call it a new process has started and been assigned the same ID.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top