Open Process Failing
Open Process Failing
(OP)
Using VB6 I am attempting to terminate a process which is running under a different user to the VB application.
I have got the process ID but when attempting to get a handle to the process using the following code I always get a return value of 0.
handle = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, ProcessID)
Both PROCESS_QUERY_INFORMATION and PROCESS_VM_READ have been setup as constants with values 1024 and 16 respectivly.
Can anyone help?
Thanks,
-Ian
I have got the process ID but when attempting to get a handle to the process using the following code I always get a return value of 0.
handle = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, ProcessID)
Both PROCESS_QUERY_INFORMATION and PROCESS_VM_READ have been setup as constants with values 1024 and 16 respectivly.
Can anyone help?
Thanks,
-Ian
RE: Open Process Failing
I expect it will return 5 (ERROR_ACCESS_DENIED) because I don't think you are allowed to open a process of another user.
Marcel
RE: Open Process Failing
Thanks,
-Ian
RE: Open Process Failing
1. Using FindWindow to search for the main window of the application and call SendMessage to send it a WM_CLOSE or WM_QUIT message.
2. Suppose the app is called app.exe
- copy the new program to appnew.exe
- call MoveFileEx to move appnew.exe to app.exe, using the flags MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING.
This will overwrite app.exe with appnew.exe when the system is rebooted.
Marcel
RE: Open Process Failing
Is it possible to get information such as the program name etc. from either the window handle or the process id?
Thanks,
Ian
RE: Open Process Failing
The GetWindowModuleFileName function retrieves the full path and file name of the module associated with the specified window handle.
Syntax
UINT GetWindowModuleFileName( HWND hwnd,
LPTSTR lpszFileName,
UINT cchFileNameMax
);
Parameters
hwnd
[in] Handle to the window whose module file name will be retrieved.
lpszFileName
[out] Pointer to a buffer that receives the path and file name.
cchFileNameMax
[in] Specifies the maximum number of TCHARs that can be copied into the lpszFileName buffer.
Return Value
The return value is the total number of TCHARs copied into the buffer.
Marcel