Re: Obtain the process id for a given filename
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 03/25/04
- Next message: McKirahan: "Re: Array Trouble"
- Previous message: Torgeir Bakken \(MVP\): "Re: Scheduled Task"
- In reply to: David Wang [Msft]: "Re: Obtain the process id for a given filename"
- Next in thread: David Wang [Msft]: "Re: Obtain the process id for a given filename"
- Reply: David Wang [Msft]: "Re: Obtain the process id for a given filename"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 25 Mar 2004 22:55:53 +1100
Hello David, and thanks for trying to help.
I was already aware of the tools you mention, but I
was asked to write such a function, if at all possible.
It seems there are no APIs to do this, and I will need
to resort to some low level code, yikes :-).
Thanks again.
Chris Val
"David Wang [Msft]" <someone@online.microsoft.com> wrote in message
news:%23G39AlhEEHA.624@TK2MSFTNGP10.phx.gbl...
| Use a tool like NTHANDLE at www.sysinternals.com to do what you want.
|
| You pass in a filename, and NTHANDLES returns the process name/IDs that have
| a handle open.
|
| FYI: your question is really "how do I obtain the processes that have a
| handle open to a given file".
|
| --
| //David
| IIS
| This posting is provided "AS IS" with no warranties, and confers no rights.
| //
| "Chris ( Val )" <chrisval@bigpond.com.au> wrote in message
| news:c3s4pi$2bptrc$1@ID-110726.news.uni-berlin.de...
| Hi Tom - thanks for the help.
|
| I have seen examples of this previously, but it's not
| really what I was looking to do. Perhaps I can explain
| what I'm after with some sample code:
|
| Private Function GetPID( ByVal filename As String ) As Long
| '
| Dim Result As Long
|
| Result = 'Do whatever it takes to get the PID associated
| 'with the program that has the file locked...
|
| GetPID = Result
| '
| End Function
|
| Once I get the PID, then I guess the easy part is running
| an query on the Win32_Process class, to obtain the Name
| property, etc...
|
| It's a VB type function, but I hope it explains better
| what I want to do.
|
| Thanks.
| Chris Val
|
|
| "Tom Lavedas" <tlavedas@hotmail.remove.com> wrote in message
| news:1291a01c411a7$65aeed70$a401280a@phx.gbl...
| | Her's an example of one way that finds all instances of
| | running processes that match a supplied name ...
| |
| | sComputer = "."
| | sAppName = "Excel.exe" ' for example
| |
| | set oWMIService = GetObject("winmgmts:" _
| | & "{impersonationLevel=impersonate}!\\" _
| | & sComputer & "\root\cimv2")
| |
| | Set cThreadList = oWMIService.ExecQuery _
| | ("Select * from Win32_Process where Name = '" _
| | & sAppName & "'",, 48)
| |
| | For Each oThread in cThreadList
| | s = s & oThread.ProcessID & ", "
| | Next
| | wsh.echo "Process ID(s):", _
| | Replace(s & "None Found", ", None Found", "")
| |
| | Tom Lavedas
| | ===========
| |
| | >-----Original Message-----
| | >Hi all - I'm finding it really difficult to find a way
| | >to do this (if at all possible ). Does anyone know of
| | >a way to obtain the process id of a filename ?
| | >
| | >Any help appreciated.
| | >
| | >Cheers.
| | >Chris Val
| | >.
| | >
|
|
|
- Next message: McKirahan: "Re: Array Trouble"
- Previous message: Torgeir Bakken \(MVP\): "Re: Scheduled Task"
- In reply to: David Wang [Msft]: "Re: Obtain the process id for a given filename"
- Next in thread: David Wang [Msft]: "Re: Obtain the process id for a given filename"
- Reply: David Wang [Msft]: "Re: Obtain the process id for a given filename"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|