0

I'm trying to make the working directory of a cmd process persistent, so that I can send multiple commands in succession to it over tcp.

I understand how to set the working directory when I start the process

proc.StartInfo.WorkingDirectory = something;

But after I start and wait for the process to exit, how can I get the current working directory in case "cd" was used?

Dmiters
  • 2,011
  • 3
  • 23
  • 31
  • Seems this is not trivial. Check http://stackoverflow.com/questions/2967650/is-it-possible-to-determine-the-working-directory-of-another-process – Kugel Feb 05 '13 at 02:46
  • 2
    Note that duplicate answer is Win API (`CreateRemoteThread`/`GetCurrentWorkingDirectory`), so you'd still need to inject your code in other process (have fun to implement .Net code to do so)... PInvoke for CreateRemoteThread would be an easy part... – Alexei Levenkov Feb 05 '13 at 02:51
  • Don't do this. The working directory can easily change, it is not under your control. If you could get it then that still doesn't mean it is accurate, the program could have changed it a microsecond later. – Hans Passant Feb 05 '13 at 04:31

0 Answers0