473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to extract filename information from running processes ?

Hi :-)
I am creating a software that will save the present state of all the
applications running on the desktop (WinXP).

Can anyone point out the method to extract the filenames from the
handles (or otherwise) of the files that are being accessed by
processes and programs ?

For example : If I have opened xyz.docx in MS Word 2007 then I want to
find out the name of the file ("xyz.docx") and its complete path
through some mean which could be either :

1. Reading or extracting information from the Word 2007 process
handle.
2. Through another non- handle based general method.

Kindly help !

Regards,

Aditya

May 23 '07 #1
3 2626
Hello adimangla,

Everything you need to do is enumerate all processes and find the process
to which your handle belongs to.
..NET doesn't provide the AFI for this, you need to dive deeper, more deep
then WINAPI - to the nt.dll level, where you can find undocumented ZwQueryObject().

Using this methods is not a simple task, because it returns name and info
about handle belonging to the YOUR process.
So, you need to perform additional task - use DuplicateHandle() to bring
external handle to your process.

I recomend you to study this sample http://www.codeguru.com/Cpp/W-P/syst...icle.php/c2827

which provide all functional u requre.

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

aHi :-)
aI am creating a software that will save the present state of all the
aapplications running on the desktop (WinXP).
aCan anyone point out the method to extract the filenames from the
ahandles (or otherwise) of the files that are being accessed by
aprocesses and programs ?
a>
aFor example : If I have opened xyz.docx in MS Word 2007 then I want
ato find out the name of the file ("xyz.docx") and its complete path
athrough some mean which could be either :
a>
a1. Reading or extracting information from the Word 2007 process
ahandle.
a2. Through another non- handle based general method.
aKindly help !
a>
aRegards,
a>
aAditya
a>

May 23 '07 #2
Hi,

"adimangla" <ad******@gmail.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
Hi :-)
I am creating a software that will save the present state of all the
applications running on the desktop (WinXP).
So in other words, you are trying to create a "hibernation" features

Can anyone point out the method to extract the filenames from the
handles (or otherwise) of the files that are being accessed by
processes and programs ?
Can be done, it's a PITA to make it, be ready to P/invoke as crazy as well
as creating some unmanaged code (and not a trivial one)
For example : If I have opened xyz.docx in MS Word 2007 then I want to
find out the name of the file ("xyz.docx") and its complete path
through some mean which could be either :

1. Reading or extracting information from the Word 2007 process
handle.
2. Through another non- handle based general method.
What you want to do is not easyly done, as a matter of fact is a SUPER
complex process that maybe only the OS can do succesfuly.

I suggest you to look another project.
May 23 '07 #3
On Wed, 23 May 2007 06:18:14 -0700, adimangla <ad******@gmail.comwrote:
Hi :-)
I am creating a software that will save the present state of all the
applications running on the desktop (WinXP).

Can anyone point out the method to extract the filenames from the
handles (or otherwise) of the files that are being accessed by
processes and programs ?
As a very basic example of where this is going to fail:

What are you planning to do about applications that behave like Notepad?
That is, they open a file and read the data, and then just close it again,
working solely from a copy of the data in memory. Without very specific
information about the internal data structures for the application *and*
complete access to that process's virtual address space, it is impossible
to determine where the file came from. And if the application doesn't
save the original file location anywhere (Notepad does, but there's no
requirement that it should), you're out of luck. The information is
simply not there to be retrieved.

And in any application, what do you plan to do when the user hasn't saved
the document yet?

Now, all that said, you certainly can achieve with at least some limited
success what you're trying to do. But your success *will* be limited, and
you definitely cannot literally "save the present state of all the
applications running on the desktop". There is a LOT more to the "present
state" than just the filenames of the files a given application has open
at the moment. Even if you could reliably get all of the filenames of all
the original source data for which there *are* filenames, that doesn't
give you anywhere close to all of the information about the application's
"present state", and that doesn't even consider situations in which the
user hasn't saved the application's documents yet, or applications that
don't even have a document-oriented user-interface.

In any case, whatever it is you plan to do, I'm pretty confident that
managed code isn't going to be the right place to do it. You can't get
access to what you apparently want access to from managed code.

Pete
May 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joe | last post by:
I'm trying to get the location of the image uisng start = s.find('<a href="somefile') + len('<a href="somefile') stop = s.find('">Save File</a></B>', start) fileName = s and then construct the...
3
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is...
2
by: Kumar | last post by:
Hi Folks, I would like to develop one custom application using asp.net,C#,SQL server for tracking all our company servers. Most of the functionality is similar to HP Systems Insight Manager ...
4
by: Dave | last post by:
I am writing a C# app in which I need to enumerate the processes running on the PC. I have succesfully done this as follows (assuming the app is running on NT4, XP, 2000 or 2003): ...
9
by: chrisspencer02 | last post by:
I am looking for a method to extract the links embedded within the Javascript in a web page: an ActiveX component, or example code in C++/Pascal/etc. I am looking for a general solution, not one...
8
by: Fabian Braennstroem | last post by:
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different...
0
by: kissii | last post by:
Hi , i am new to VB. I want to know what are the processes running in system. what i am thinking is if i can get how to access system tray information, i can get all the processes/services...
2
by: Fabian Braennstroem | last post by:
Hi, I would like to delete a region on a log file which has this kind of structure: #------flutest------------------------------------------------------------ 498 1.0086e-03 2.4608e-04...
5
by: Steve | last post by:
Hi all Does anybody please know a way to extract an Image from a pdf file and save it as a TIFF? I have used a scanner to scan documents which are then placed on a server, but I need to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.