AutoHotkey Community

It is currently May 26th, 2012, 3:37 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Find out a process name?
PostPosted: June 26th, 2005, 10:01 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2005, 3:55 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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%
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2005, 8:04 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
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%
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2005, 11:51 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2005, 9:21 pm 
Thanks for the reply, that is excellent. Great software, by the way.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 29th, 2005, 12:13 am 
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;


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 29th, 2005, 1:23 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2005, 9:23 pm 
Offline

Joined: July 25th, 2005, 10:20 pm
Posts: 139
Location: Richmond, Virginia
Super! A get-full-path-of-process feature would be great.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Full path
PostPosted: August 29th, 2005, 11:33 pm 
Offline

Joined: July 30th, 2004, 8:50 pm
Posts: 192
:D 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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Full path
PostPosted: August 30th, 2005, 5:29 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
skrommel wrote:
:D You can find the full path of a process by reading the registry.

Cool 8) Thanks :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 30th, 2005, 4:30 pm 
the registry entries are not available on windows 2000 :(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 30th, 2005, 5:06 pm 
Offline

Joined: July 25th, 2005, 10:20 pm
Posts: 139
Location: Richmond, Virginia
Ditto. It didn't work on my Windows 2000 computer either.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Only XP
PostPosted: September 14th, 2005, 10:17 am 
Offline

Joined: July 30th, 2004, 8:50 pm
Posts: 192
:( Yes, only XP. I think it's used in the recent programs list on the new start menu.

Skrommel


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 3:22 am 
Offline

Joined: December 15th, 2004, 10:24 pm
Posts: 303
Location: United States
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>>


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Full path
PostPosted: November 5th, 2005, 5:47 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
skrommel wrote:
:D 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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: DataLife and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group