AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Find out a process name?
Goto page 1, 2, 3  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
grumpy
Guest





PostPosted: Sun Jun 26, 2005 9:01 pm    Post subject: Find out a process name? Reply with quote

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

PostPosted: Mon Jun 27, 2005 2:55 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
corrupt



Joined: 29 Dec 2004
Posts: 2485

PostPosted: Mon Jun 27, 2005 7:04 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Mon Jun 27, 2005 10:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
grumpy
Guest





PostPosted: Tue Jun 28, 2005 8:21 pm    Post subject: Reply with quote

Thanks for the reply, that is excellent. Great software, by the way.
Back to top
Guest






PostPosted: Tue Jun 28, 2005 11:13 pm    Post subject: Reply with quote

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

PostPosted: Wed Jun 29, 2005 12:23 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Litmus Red



Joined: 25 Jul 2005
Posts: 139
Location: Richmond, Virginia

PostPosted: Mon Aug 22, 2005 8:23 pm    Post subject: Reply with quote

Super! A get-full-path-of-process feature would be great.
Back to top
View user's profile Send private message
skrommel



Joined: 30 Jul 2004
Posts: 190

PostPosted: Mon Aug 29, 2005 10:33 pm    Post subject: Full path Reply with quote

Very Happy 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
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2485

PostPosted: Tue Aug 30, 2005 4:29 am    Post subject: Re: Full path Reply with quote

skrommel wrote:
Very Happy You can find the full path of a process by reading the registry.

Cool Cool Thanks Very Happy
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Tue Aug 30, 2005 3:30 pm    Post subject: Reply with quote

the registry entries are not available on windows 2000 Sad
Back to top
Litmus Red



Joined: 25 Jul 2005
Posts: 139
Location: Richmond, Virginia

PostPosted: Tue Aug 30, 2005 4:06 pm    Post subject: Reply with quote

Ditto. It didn't work on my Windows 2000 computer either.
Back to top
View user's profile Send private message
skrommel



Joined: 30 Jul 2004
Posts: 190

PostPosted: Wed Sep 14, 2005 9:17 am    Post subject: Only XP Reply with quote

Sad Yes, only XP. I think it's used in the recent programs list on the new start menu.

Skrommel
Back to top
View user's profile Send private message Visit poster's website
Decarlo110



Joined: 15 Dec 2004
Posts: 303
Location: United States

PostPosted: Mon Sep 26, 2005 2:22 am    Post subject: Reply with quote

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
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1237

PostPosted: Sat Nov 05, 2005 4:47 pm    Post subject: Re: Full path Reply with quote

skrommel wrote:
Very Happy 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
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group