Jump to content
misc_bb

Getting PID of winword.exe based on filename

Recommended Posts

I'm able to get the PID of a processname (ex: winword.exe) but interested of getting the PID of winword.exe based on a specific filename, is this possible? I was able to look capture the PID from winword but if there are multiple instance I can't kill all instance but only a specific one. I'm not so familiar with Winapi handling, based on this post: Delphi Get the handle of a EXE he is trying to change his approach from 'Window name' to an Exe name. But parameter @processid needs to be specified. How can I get the processid in this case based on filename or window name?

Share this post


Link to post

There is no easy way to identify which file(s) a process has open (there are hard ways, though).  But you are assuming that WinWord actually keeps the file open, and is not simply reading the whole file into memory and then closing the file, operating on the memory until you save again.

 

You are most likely just going to have to search through window titles to know which WinWord window is operating on which file.

Share this post


Link to post
2 hours ago, Remy Lebeau said:

But you are assuming that WinWord actually keeps the file open, and is not simply reading the whole file into memory and then closing the file, operating on the memory until you save again.

Actually that's what Word does. It occupies the opened file for the whole edit cycle blocking it from access

Share this post


Link to post

Thank you for the idea on this topic.

I don't want to go the hard way :classic_biggrin: I can probably do this one at a time. I'll just terminate winword after every documents' final save until the next document opens.

Share this post


Link to post
1 hour ago, David Heffernan said:

Does Word use a separate process for each open document? 

No. With two opened documents task manager show a single PID.

 

image.thumb.png.77e9a00569d7bbbdc89a67182369ae05.png

 

Share this post


Link to post

Can anyone else open Word there? Because if so, you have a problem.

Share this post


Link to post
9 hours ago, Lajos Juhász said:

No. With two opened documents task manager show a single PID.

 

image.thumb.png.77e9a00569d7bbbdc89a67182369ae05.png

 

Which means the original idea was doomed. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×