44

So, I know you can create a shortcut to an administrator-level command prompt (as described in this question), but what I'm seeing is that whenever I use such a shortcut, it always drops me into c:\windows\system32\ path.

I've tried specifying that shortcut's properties to set the "start in" path I need, but to no avail. It seems any time I run cmd.exe "As Administrator," it completely disregards the shortcut's paths and sticks to c:\windows\system32\

Any suggestions on how to get Windows 7 to respect the shortcut's "start in" path?

10 Answers 10

53

I found a way around this. In the shortcut, change the command line to:

C:\Windows\System32\cmd.exe /k "cd c:\"

In this case it changes the starting directory to the root of C:. You can set your own parameters.

4
  • But what is the reason? – ziyuang Feb 5 '15 at 1:04
  • You're still specifying a fixed directory instead of landing in the same directory from which the shortcut is activated. – bvj Mar 11 '15 at 23:58
  • If you want to run a program in the directory, append (without quotes) "& myprogramname.exe" at the end of the command line above. – trebormf Mar 23 '16 at 20:40
  • "pushd c:\" would also work when setting up a administrative cmd shortcuts – bshea Aug 12 '18 at 16:29
10

It will happen if the place where you want to open your command prompt is on a different drive than the shortcut is. The solution is to put an additional command in the shortcut:

C:\Windows\System32\cmd.exe /k "a: & cd a:\something"

In this case it will change to the drive a: from the current drive, and than open the a:\something folder. The & operator is used to put multiple commands in a single line at the windows command prompt.

2
  • 6
    cd /d a:\something will change to a different drive and directory – Luke Jan 9 '13 at 23:32
  • This would work too: pushd a:\something – Br.Bill Jun 24 '16 at 22:28
3

Launch an elevated Command Prompt from the context menu

To add the Open Command Window Here (Administrator) option to the context menu for file system folders, use the following REG file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open Command Window Here (Administrator)"

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

To add the entry to Computer (My Computer) context menu, use the following REG file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\runas]
@="Open Command Prompt (Administrator)"

[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\runas\command]
@="cmd.exe"

Usage

Copy the above contents to Notepad, and save the file with .REG extension. Then right-click the REG file and choose Merge.

Source

2
  • This is a good suggestion, but not quite what I'm looking for. I'm looking for a way to create an arbitrary shortcut, which I can pin to the taskbar. – Alex Beynenson Dec 28 '09 at 2:39
  • i'm not sure if this is possible, unless you change the start directory for CMD globally: To change default path where cmd starts add/edit REG_SZ Autorun in HKEY_CURRENT_USER\Software\Microsoft\Command Processor replacing the Value Data with a folder or directory preceded by a CD\ – Molly7244 Dec 28 '09 at 3:12
3

This is what I do:

First I create a shortcut for cmd.exe and place it into a directory that I will always keep from computer to computer.. e.g. c:\PersonalData\Windows Customize\Admin then I edit the shortcut to read as below (Domain and AdminUser you will need to change)

C:\Windows\System32\runas.exe /user:domain\AdminUser /savecred "C:\Windows\System32\cmd.exe /k cd c:\PersonalData"

Then I create a toolbar on my taskbar that points to the "Admin" Folder.. this is where I keep all my admin tools ... this works on WinXP and Windows 7..

Another thing that I will do is change the color of my background of this cmd prompt that easily identifies that I have my admin credentials open... if you want to be more secure take out the /savecred then it will prompt you for your admin password every time

2

Easiest option I have found is to add a registry key. Run the following from an elevated command prompt:

REG ADD "HKLM\SOFTWARE\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "CD /D C:\"

NOTE: Close the command prompt afterwards and reopen and it will change to the root of the C drive.

This will work for all users.

Alternatively adding to current user works too (put it in a logon script, startup folder etc) but this would be dynamic of course.

1
  • thank you, start in doesn't work...this solves it all the time. – Dave Horner Apr 27 '17 at 13:16
1

Update on @Molly7244's answer.

  1. Add nice icons
  2. Only visible on Shift (as you are used to with standard cmd window)
  3. Hotkey on 'a'

enter image description here

Windows Registry Editor Version 5.00

;Add 'Open command window here (Administrator)' context menu
;Extended means it shows on shift key
;Hotkey on 'a'

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@="Open command window here (&Administrator)"
"Extended"=""
"NoWorkingDirectory"=""
"Icon"="C:\\Windows\\system32\\imageres.dll,-5324"

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open command window here (&Administrator)"
"Extended"=""
"NoWorkingDirectory"=""
"Icon"="C:\\Windows\\system32\\imageres.dll,-5324"

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""


;Add icon also to standard 'Open command window here'

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmd]
"Icon"="C:\\Windows\\system32\\imageres.dll,-5323"

[HKEY_CLASSES_ROOT\Directory\shell\cmd]
"Icon"="C:\\Windows\\system32\\imageres.dll,-5323"
0

You can right click CMD, select Properties and in the "Start in" box clear whatever is there, entering: %SystemRoot%\system32. Click OK.

1
  • This is not a good answer, the question explicitly said that the start in parameter isn't working, something which I can confirm in my Windows 10. – pgr Apr 6 '16 at 10:16
0

The correct answer was given by Peter, but if you want to switch to a drive other than c: (assuming Windows is on c:) is to use

C:\Windows\System32\cmd.exe /k "cd /d d:\some_directory"
0

If you are running a *.bat file through a shortcut marked with "run as administrator" you can change to the folder of the *.bat file by adding in the beginning of the *.bat file the following row: cd %~dp0

1
  • maybe you need converted to a comment rather than an answer; just flag and ask. – Pillsbury IT Doughboy Jul 11 '17 at 14:19
0

I use Powershell ISE instead - it has tabs!!

In windows 10 this worked for me

I changed the properties/start in in following location

drive:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tools

Command prompt shortcut was here

If you use powershell they live under

AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell

I changed the Start-in field to D:\data\local and now all new instances launch there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.