8

I have a shortcut on my desktop which opens a command prompt with many arguments that I need. I set the 'start in' field to d:\ and it works as expected (the prompt starts in d:). When I choose Advanced -> run as administrator and then open the shortcut, it starts in C:\Windows\System32, even though I have not changed the 'start in' field. How can I get it to start in d:\?

Joseph Daigle
  • 47,650
  • 10
  • 49
  • 73
Sam S
  • 118
  • 1
  • 5
  • This is actually a general problem with shortcuts that applies to more than just `cmd`, or indeed `cmd` scripts. Compare https://stackoverflow.com/q/672693/340790 . – JdeBP Mar 11 '21 at 08:45

1 Answers1

10

If you use the /k argument, you can add a single line to execute a change drive and change directory. For instance:

C:\Windows\System32\cmd.exe /k "d: & cd d:\storage"

Using & you can string together many commands on one line.

Edit: You can also change drive with the cd command alone "cd /d d:\storage". Thanks to Adam Mitz for the comment.

Joseph Daigle
  • 47,650
  • 10
  • 49
  • 73
  • I did not know the change directory command did that. Good to know. – Joseph Daigle Sep 16 '08 at 01:29
  • 1
    As for "why" it does this, according to a Microsoft support engineer , [executing from system32 when running as admin is by design](http://answers.microsoft.com/en-us/windows/forum/windows_8-performance/command-prompt-ignores-start-in-location-when/b6c1c59c-b9a9-48bf-be9c-867e5b796f42): `"This issue is by deign as a result of which the commandline activities will run as admin from the default location as it will not start using the Start-in location or from the quick launch toolbar."` – cod3monk3y Dec 07 '13 at 20:17