1

The goal here is to start an EXE in elevated mode and make sure the Working Directory is set. It does not have to be done with the 'Start-Process' command.

I have these 2 commands:

powershell Start-Process -FilePath notepad.exe -WorkingDirectory "C:\Users\xyz\Documents"

This one sets the WD so that when I click "File> Save as" I can see the WD shown in the popup.

powershell Start-Process -FilePath notepad.exe -WorkingDirectory "C:\Users\xyz\Documents" -Verb Runas

I want to achieve the results of the 1st command, in the 2nd elevated command. Thanks

conanDrum
  • 215
  • 2
  • 7
  • not really... because powershell being the executable that is started there, can accept a command 'cd c:\xyz', whereas notepad does not accept that command. – conanDrum Jul 15 '21 at 17:19
  • If I change to `C:\Users\xyz\Desktop` the default saving directory for notepad is still Documents for me tho. – Santiago Squarzon Jul 15 '21 at 17:23
  • can you elaborate? I do not understand. – conanDrum Jul 15 '21 at 17:27
  • If I change `-WorkingDirectory "C:\Users\xyz\Documents"` for some other random directory and use `Start-Process` (without `-Verb RunAs`) I would still see __My Documents__ as a the default saving directory on notepad. – Santiago Squarzon Jul 15 '21 at 17:44
  • That is corect. It is a known fact that WorkingDirectory is not honored when elevated. I am looking for a solution. – conanDrum Jul 15 '21 at 17:51
  • @conanDrum, please see the [answer](https://stackoverflow.com/a/68399496/45375) I've just added to the linked duplicate (command at the bottom). – mklement0 Jul 15 '21 at 19:09
  • @SantiagoSquarzon, that is true for Notepad, specifically, but I assume Notepad is just being used as an example. To put it differently: Notepad decides what save / open location to offer independently of its process' working directory, but other applications may require a specific, given working dir. – mklement0 Jul 15 '21 at 19:10
  • @mklement0 yes I understand, my first guess is that for notepad specifically, the default saving folder for each user is set on windows registry. – Santiago Squarzon Jul 15 '21 at 19:18

0 Answers0