How to retrieve process path?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ineedh3lp
Junior Coder
Posts: 26
Joined: Thu Nov 04, 2010 1:11 am

How to retrieve process path?

Post by ineedh3lp » Wed May 04, 2011 4:25 pm

Hello!

Could you please show me how to retrieve an application's path if the process exists?

For example, if I have an application called Core Temp.exe running, how can I get to find out its path (C:\Program Files\Core Temp\Core Temp.exe) using MacroScheduler scripting?

Thank you!

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed May 04, 2011 8:36 pm

Here is a simple example that should get you going on the right track.
You will need to tweak it for your exact needs.

Code: Select all

//get process commandline

Let>RP_WAIT=1
Let>RP_WINDOWMODE=0



Run>WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid

ReadFile>c:\processlist.txt,processlist
MessageModal>processlist

ineedh3lp
Junior Coder
Posts: 26
Joined: Thu Nov 04, 2010 1:11 am

Post by ineedh3lp » Wed May 04, 2011 9:17 pm

Excellet!. Thank you. I'm using this

Code: Select all

Run>WMIC /OUTPUT:H:\TEMP\ProcessList.txt PROCESS get ExecutablePath
and I get a text file containing only the paths of the currently running applications (like: C:\Program Files\zabkat\xplorer2\xplorer2_64.exe ).

Knowing the name of the executable (xplorer2_64.exe), how can I extract the path from the text file to a variable? or is there a way to generate a text file with information about a single process so I can read the line (that always keeps the same position) containing the path?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Thu May 05, 2011 4:53 pm

something like this should work for you.

Code: Select all

  //Change this variable to what you are looking for
  Let>TargetProcess=wscntfy.exe
  Let>k=1
Label>start
  ReadLn>H:\TEMP\processlist.txt,k,line
  If>line=##EOF##,finish
  Position>TargetProcess,line,1,StartPos
  If>StartPos>0
    ExtractFilePath>line,path
    MessageModal>filepath to %TargetProcess% is %path%
    Goto>finish
  Endif
  Let>k=k+1
  Goto>start
Label>finish

ineedh3lp
Junior Coder
Posts: 26
Joined: Thu Nov 04, 2010 1:11 am

Post by ineedh3lp » Thu May 05, 2011 5:10 pm

Works! Thank you!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts