Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p><strong>UPDATE:</strong> This is <strong>not</strong> the solution, see the comments to this answer: <em>"As Janm said .Modules[0].FileName (or MainModuile.FileName) gives the location of the executable running in that process. I'm looking to find the current working directory (that can be changed using the CD or CHDIR commands)."</em></p> </blockquote> <p>You could use <strong>System.Diagnostics Namespace</strong>. Here an example as C# console application. From the filename you can easily extract the Path information (System.IO.Path...).</p> <p>You would make sure to have the permissions (run as admin) to do this. </p> <p>Hope this helps. Here is the <strong>working code</strong> (tested):</p> <pre><code>using System; using System.Diagnostics; using System.IO; namespace Test { class Program { static void Main(string[] args) { Process[] procList = Process.GetProcessesByName("cmd"); string sFileName; for (int i = 0; i &lt; procList.Length; i++ ) { Console.Write(procList[i].Id); Console.Write(" "); try { sFileName = procList[i].Modules[0].FileName; Console.Write("("); Console.Write(Path.GetFileName(sFileName)); Console.Write("): "); Console.WriteLine(Path.GetDirectoryName(sFileName)); } catch (Exception ex) { // catch "Access denied" etc. Console.WriteLine(ex.Message); } } } } } </code></pre> <p>Here the the <strong>output</strong> on my machine (I've opened four command lines):</p> <p><a href="http://img236.imageshack.us/img236/3547/processworkingdirvn4.png" rel="nofollow noreferrer">alt text http://img236.imageshack.us/img236/3547/processworkingdirvn4.png</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload