×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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

(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

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.

Marcel

RE: Open Process Failing

(OP)
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.

Thanks,

-Ian

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.

Marcel

RE: Open Process Failing

(OP)
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?

Thanks,

Ian

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.

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

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