0

I'm aware of the normal ways to change the working directory from your C# code, things like SetCurrentDirectory and such. What I want to know, is how to change the directory and have this change persist after the program terminates. This seems like a very basic task, and yet, I haven't been able to find anything about the problem.

Nik Tedig
  • 453
  • 2
  • 6
  • Why do you need this? do you have calls that rely on the *Current Directory*, as apposed to the location of the executing/entry assembly ? – TheGeneral Sep 19 '20 at 22:35
  • You can save the desired value in application settings or in a file somewhere or in the registry for example. What do you prefer? Hence at each startup, you can read it as well as save if change is needed or on the first initialization. –  Sep 19 '20 at 22:46
  • `persist after the program terminates` Do you mean "persist" as in (a) your program remembers it next time it runs, or (b) the parent process that launched your program has *its* current directory changed when your program runs? – dxiv Sep 19 '20 at 22:53
  • 1
    You can stop looking, that is not possible. – Hans Passant Sep 19 '20 at 23:09
  • @dxiv The latter. – Nik Tedig Sep 20 '20 at 11:14
  • @NikTedig Not possible in general, unless you also own the parent process, get it to cooperate, or hack it. Some pointers at [1](https://stackoverflow.com/questions/10811645/changing-the-directory-from-inside-a-c-program-under-windows-using-system-comman), [2](https://stackoverflow.com/questions/60339691/changing-the-current-working-directory-of-cmd-from-a-child-process), [3](https://stackoverflow.com/questions/55543814/is-it-possible-to-change-the-directory-of-a-windows-console-from-an-app). – dxiv Sep 20 '20 at 16:16

0 Answers0