Windows 7 Administrator Command Prompt "Start in" Path

42

17

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?

Alex Beynenson

Posted 2009-12-24T18:56:16.657

Reputation: 717

Answers

49

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.

Peter

Posted 2009-12-24T18:56:16.657

Reputation: 506

But what is the reason? – ziyuang – 2015-02-05T01:04:17.123

You're still specifying a fixed directory instead of landing in the same directory from which the shortcut is activated. – bvj – 2015-03-11T23:58:15.580

If you want to run a program in the directory, append (without quotes) "& myprogramname.exe" at the end of the command line above. – trebormf – 2016-03-23T20:40:24.163

"pushd c:" would also work when setting up a administrative cmd shortcuts – bshea – 2018-08-12T16:29:01.530

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.

Pásztor Dávid

Posted 2009-12-24T18:56:16.657

Reputation: 101

This would work too: pushd a:\something – Br.Bill – 2016-06-24T22:28:08.600

5cd /d a:\something will change to a different drive and directory – Luke – 2013-01-09T23:32:44.237

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

AquaRabbit

Posted 2009-12-24T18:56:16.657

Reputation: 31

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

Molly7244

Posted 2009-12-24T18:56:16.657

Reputation:

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 – 2009-12-28T02:39:45.283

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\ – None – 2009-12-28T03:12:49.550

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.

Neil Cole

Posted 2009-12-24T18:56:16.657

Reputation: 21

thank you, start in doesn't work...this solves it all the time. – Dave Horner – 2017-04-27T13:16:21.137

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"

Qwerty

Posted 2009-12-24T18:56:16.657

Reputation: 308

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

Jarmo Palomäki

Posted 2009-12-24T18:56:16.657

Reputation: 1

maybe you need converted to a comment rather than an answer; just flag and ask. – Pimp Juice IT – 2017-07-11T14:19:26.630

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

Kalpesh Soni

Posted 2009-12-24T18:56:16.657

Reputation: 101

0

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

problem solver

Posted 2009-12-24T18:56:16.657

Reputation: 9

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 – 2016-04-06T10:16:47.223

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"

tst

Posted 2009-12-24T18:56:16.657

Reputation: 41