Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Find out a process name?


  • Please log in to reply
30 replies to this topic
grumpy
  • Guests
  • Last active:
  • Joined: --
It is possible, using the Process command, to find a PID from the process's name, but can the opposite be done?

i.e. Can a process name be found from its ID?

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
If the process has any windows, even a hidden window, then you can use WinGet to do it:
DetectHiddenWindows on
IfWinExist ahk_pid %ThePID%
{
     WinGet, ProcessName, ProcessName  ; Uses the window found above.
     MsgBox %ProcessName%
}


corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Out of curiosity, how would you retrieve the full path? This seems to only return "NOTEPAD.EXE"
DetectHiddenWindows on 

Run, Notepad.exe ,,,ThePID

WinWait, Untitled - Notepad

IfWinExist ahk_pid %ThePID% 

{ 

     WinGet, ProcessName, ProcessName  ; Uses the window found above. 

     MsgBox %ProcessName% 

}


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I know there's a way to get the full path of a process via the API, but I don't know it yet. If you find it, please let me know because this feature has been requested several times.

grumpy
  • Guests
  • Last active:
  • Joined: --
Thanks for the reply, that is excellent. Great software, by the way.

  • Guests
  • Last active:
  • Joined: --
here

For managing processes Windows API provide two different libraries are present:
PSAPI.DLL functions (in psapi.dll) - avail in Windows NT and 2k/XP
ToolHelp functions (in kernel32.dll) - avail in Windows 9x/ME/2k/XP

As you can see, if you want to support Windows 9x then you must code using ToolHelp API and if you want to support WinNT then you have to code using PSAPI. Also note that these different libraries use different data structures to present and to manage processes.


PSAPI does not have one function that help us build one data structure to fit our needs. That is why I will use the following PSAPI functions in addition:

GetModuleFileNameEx() - given a process handle and a module base it will return us its full path.


typedef struct tagPROCESSENTRY32
{
DWORD dwSize;
DWORD cntUsage;
DWORD th32ProcessID;
ULONG_PTR th32DefaultHeapID;
DWORD th32ModuleID;
DWORD cntThreads;
DWORD th32ParentProcessID;
LONG pcPriClassBase;
DWORD dwFlags;
TCHAR szExeFile[MAX_PATH];
} PROCESSENTRY32, *PPROCESSENTRY32;


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for the info. I somehow missed that during my previous Google and MSDN search on the subject.

I will try to apply this method to provide a get-full-path-of-process feature, even if there is no way easy way to support the same on Windows 9x.

Litmus Red
  • Members
  • 139 posts
  • Last active: Nov 03 2005 05:01 PM
  • Joined: 25 Jul 2005
Super! A get-full-path-of-process feature would be great.

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:D You can find the full path of a process by reading the registry.


FULLPATH:
WinGet,window,Id,A
WinGet,file,ProcessName,ahk_id %window%
  Loop,HKEY_CURRENT_USER,Software\Microsoft\Windows\ShellNoRoam\MUICache,0,0
  {
    IfInString,A_LoopRegName,%file%
    {
      RegRead,info
      path=%A_LoopRegName%
      Break
    }
  }
MsgBox,%path%
Return


corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

:D You can find the full path of a process by reading the registry.

Cool 8) Thanks :D

  • Guests
  • Last active:
  • Joined: --
the registry entries are not available on windows 2000 :(

Litmus Red
  • Members
  • 139 posts
  • Last active: Nov 03 2005 05:01 PM
  • Joined: 25 Jul 2005
Ditto. It didn't work on my Windows 2000 computer either.

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:( Yes, only XP. I think it's used in the recent programs list on the new start menu.

Skrommel

Decarlo110
  • Members
  • 303 posts
  • Last active: Feb 12 2006 02:15 AM
  • Joined: 15 Dec 2004

You can find the full path of a process by reading the registry.

I have Win2000, but from my understanding of the posted script, if you have two different programs which are named the same, in their own program folders, and you have both running at the same time, the script will return the same path for both programs.

When the full-path feature is implemented in Ahk, it should be able to identify which programs are running, even if many are identically named. This will be especially useful, for example, in scripts written for security purposes.
1) The Open Source Definition http://www.opensourc...ition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <>

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005

:D You can find the full path of a process by reading the registry.


FULLPATH:
WinGet,window,Id,A
WinGet,file,ProcessName,ahk_id %window%
  Loop,HKEY_CURRENT_USER,Software\Microsoft\Windows\ShellNoRoam\MUICache,0,0
  {
    IfInString,A_LoopRegName,%file%
    {
      RegRead,info
      path=%A_LoopRegName%
      Break
    }
  }
MsgBox,%path%
Return



1) I couldn't find an answer through google, so:

Does anyone know how, in the following registry entry under that MUICache key (as an example only, there are lots of others) the number at the end is related to the icon within the dll?:

@C:\WINDOWS\system32\SHELL32.dll,-32517

(Which is for the "Taskbar and Start Menu" settings icon - most other Windows-related windows are also referenced this way).

This ",-32517" seems to somehow correspond to icon number 40 within SHELL32.dll. Any ideas what the relationship is? (Browsing to the MUICache key you can see plenty of others.)


2) Did the requested "get-full-path-of-process feature" make it onto the planned features list? I couldn't spot it myself.