Re: Obtain the process id for a given filename

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 03/24/04


Date: Thu, 25 Mar 2004 01:08:46 +1100

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
| >.
| >



Relevant Pages

  • Re: Obtain the process id for a given filename
    ... | Private Function GetPID(ByVal filename As String) As Long ... | Once I get the PID, then I guess the easy part is running ... | "Tom Lavedas" wrote in message ... | | running processes that match a supplied name ... ...
    (microsoft.public.scripting.wsh)
  • Re: find process PID
    ... but it needs the entire program path (wich I don't ... I'd suggest CreateProcess, if Shell looks ... You can use GetModuleFileName against any given PID. ... approach to finding running processes will vary depending on OS. ...
    (comp.lang.basic.visual.misc)
  • Re: Hidden Processes
    ... I meant that pid ... > see the process IDs if you ls /proc. ... > is information on running processes. ... Alex ...
    (comp.os.linux.security)