Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Open Process Failing

Open Process Failing

Open Process Failing

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.


Both PROCESS_QUERY_INFORMATION and PROCESS_VM_READ have been setup as constants with values 1024 and 16 respectivly.

Can anyone help?



RE: Open Process Failing

You can call GetLastError() after the failure of OpenProcess to find out why it failed.
I expect it will return 5 (ERROR_ACCESS_DENIED) because I don't think you are allowed to open a process of another user.


RE: Open Process Failing

I have check this and I am getting ERROR_ACCESS_DENIED is there anyway around this as I am attempting to overwrite a .exe file for a software upgrade and need to close the application so that the exe can be overwritten.



RE: Open Process Failing

Two ways of doing that:

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.


RE: Open Process Failing

Thanks for that I have managed to successfully close the program using the window handle.

Is it possible to get information such as the program name etc. from either the window handle or the process id?



RE: Open Process Failing

Copied from MSDN Library:

The GetWindowModuleFileName function retrieves the full path and file name of the module associated with the specified window handle.


UINT GetWindowModuleFileName(          HWND hwnd,
    LPTSTR lpszFileName,
    UINT cchFileNameMax

[in] Handle to the window whose module file name will be retrieved.
[out] Pointer to a buffer that receives the path and file name.
[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.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close