6

I am currently developing a customized CafeSuite system for my Internet Cafe. And I'm using Java and JNI (Java Native Interface) to get through the Windows Registry. But I have this module I can't get or see if it is possible to work on Windows XP.

When I commanded on the Command-line, tasklist or tlist it would return me all of the running *.exe in the system. But with all of the parameters that could be added to the line, I can't see a parameter that would return the directory or path where an *.exe was executed.

Unfortunately, I am not using any Windows Server OS and am not to rely on any firewall of UAC or User Account Control feature of the OS.

With the given means, is it possible to pursue such concept?

5
  • Do you just want to know where a process was started from, or do you need to determine this from within your app? Does it need to be command line?
    – Paul
    May 14, 2012 at 5:02
  • All yes. I need to know the pathfile of each of process return by tasklist or tlist. Also, I need it to be in the command line for me to display the results within the program I am working on.
    – David B
    May 14, 2012 at 6:02
  • Perhaps you can try using WMI calls instead. Running "wmic process list" in the command prompt lists all running processes with the full path. With some batch-fu, you could technically extract the path of a running exe if it exists.
    – NMS
    May 14, 2012 at 7:19
  • @Mart, could you provide details in regards of using wmic process list as an answer here. Thanks.
    – David B
    May 14, 2012 at 7:22
  • I could do that but that would take some time to dig around microsoft.com and research properly. If you try running that command and redirecting it to text file, you can see various properties. There is also some format specifiers and switches you could use to output that information into a CSV or XML file and to be parsed later. Add /? to any wmic command for help.
    – NMS
    May 14, 2012 at 7:44

3 Answers 3

8

In XP and above you can use the “System Information” tool, which shows the path.  You can run this from the menu at “Start” → “All Programs” → “Accessories” → “System Tools”, or from the command line as msinfo32  (or “Start” → “Run…” → msinfo32ENTER).

Click on “Software Environment” → “Running Tasks”, and the path is shown.

http://www.raymond.cc/blog/determine-program-path-from-task-manager-for-each-program-in-windows-xp-windows-server-2003/

enter image description here

2

Using Windows Powershell, if you want to do find out the path for "firefox.exe, you could do:

(Get-WmiObject -class Win32_Process -Filter 'Name="firefox.exe"').path.SubString(0, (Get-WmiObject -class Win32_Process -Filter 'Name="firefox.exe"').path.LastIndexOf('\'))

This would return:

C:\Program Files (x86)\Mozilla Firefox

Replace "firefox.exe" with desired executable.

2
  • Am I going to prompt wmic before entering the command above?
    – David B
    May 17, 2012 at 7:52
  • Not needed. But you need to run those using Windows Powershell, not the command prompt. <code>Get-WmiObject</code> is a cmdlet in Powershell. You may run it with the <code>-?</code> switch for more help info.
    – NMS
    May 21, 2012 at 8:28
0

I think this solved the problem. I have google it here about it and it worked using the commandline.

3
  • Your WMIC answer is OK but GlenG's answer is much better 'cos it's easy to remember and native. I suggest you change your accepted answer to his.
    – barlop
    Aug 28, 2014 at 22:33
  • @barlop, your comment doesn't make sense -- wmic is native to Windows since XP. Additionally, it provides a text based output which is then able to be filtered easily with tools like findstr.
    – Daniel
    Mar 24, 2015 at 17:56
  • @Daniel I agree my comment is rather strange. I do not know why I wrote that. Maybe I wasn't saying that WMIC wasn't native. I was saying Glen's answer is native and easy to remember. And in the strict boolean sense, Nano's isn't, because it's not as easy to remember, As in Glenn's meets both criteria.. nano's doesn't meet both criteria. WMIC being so large, it is a little subject in itself. but nothing wrong with it.. On a related note, He should've included the answer in his answer then it'd be a little bit more easy to remember but still not as easy to remember as Glen's..
    – barlop
    Mar 24, 2015 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .