 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
grumpy Guest
|
Posted: Sun Jun 26, 2005 9:01 pm Post subject: Find out a process name? |
|
|
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? |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10716
|
Posted: Mon Jun 27, 2005 2:55 am Post subject: |
|
|
If the process has any windows, even a hidden window, then you can use WinGet to do it:
| Code: | DetectHiddenWindows on
IfWinExist ahk_pid %ThePID%
{
WinGet, ProcessName, ProcessName ; Uses the window found above.
MsgBox %ProcessName%
} |
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Mon Jun 27, 2005 7:04 am Post subject: |
|
|
Out of curiosity, how would you retrieve the full path? This seems to only return "NOTEPAD.EXE" | Code: | DetectHiddenWindows on
Run, Notepad.exe ,,,ThePID
WinWait, Untitled - Notepad
IfWinExist ahk_pid %ThePID%
{
WinGet, ProcessName, ProcessName ; Uses the window found above.
MsgBox %ProcessName%
} |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10716
|
Posted: Mon Jun 27, 2005 10:51 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
grumpy Guest
|
Posted: Tue Jun 28, 2005 8:21 pm Post subject: |
|
|
| Thanks for the reply, that is excellent. Great software, by the way. |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Jun 28, 2005 11:13 pm Post subject: |
|
|
here
| Quote: | 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. |
| Quote: | 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. |
| Code: | 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; |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10716
|
Posted: Wed Jun 29, 2005 12:23 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Litmus Red
Joined: 25 Jul 2005 Posts: 139 Location: Richmond, Virginia
|
Posted: Mon Aug 22, 2005 8:23 pm Post subject: |
|
|
| Super! A get-full-path-of-process feature would be great. |
|
| Back to top |
|
 |
skrommel
Joined: 30 Jul 2004 Posts: 190
|
Posted: Mon Aug 29, 2005 10:33 pm Post subject: Full path |
|
|
You can find the full path of a process by reading the registry.
| Code: | 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 |
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Tue Aug 30, 2005 4:29 am Post subject: Re: Full path |
|
|
| skrommel wrote: | You can find the full path of a process by reading the registry. |
Cool Thanks  |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Aug 30, 2005 3:30 pm Post subject: |
|
|
the registry entries are not available on windows 2000  |
|
| Back to top |
|
 |
Litmus Red
Joined: 25 Jul 2005 Posts: 139 Location: Richmond, Virginia
|
Posted: Tue Aug 30, 2005 4:06 pm Post subject: |
|
|
| Ditto. It didn't work on my Windows 2000 computer either. |
|
| Back to top |
|
 |
skrommel
Joined: 30 Jul 2004 Posts: 190
|
Posted: Wed Sep 14, 2005 9:17 am Post subject: Only XP |
|
|
Yes, only XP. I think it's used in the recent programs list on the new start menu.
Skrommel |
|
| Back to top |
|
 |
Decarlo110
Joined: 15 Dec 2004 Posts: 303 Location: United States
|
Posted: Mon Sep 26, 2005 2:22 am Post subject: |
|
|
| skrommel wrote: | | 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.opensource.org/docs/definition_plain.php
2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>> |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1237
|
Posted: Sat Nov 05, 2005 4:47 pm Post subject: Re: Full path |
|
|
| skrommel wrote: | You can find the full path of a process by reading the registry.
| Code: | 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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|