I found myself opening command promp or powershell more and more often. There is one small trick that speeds it up: in explorer (to start explorer you can use win + e) press alt + d this will give focus to address bar, then type cmd  and press enter. This will start command promp at that path. This is fine, but I need to run command promp as administrator, it can be done: File –> Open command promp –> Open command promp as administrator or you can just press Alt, F, M, A. I don’t like this way, I’m so used to pressing alt + d that I wanted to type cmda press enter and start command promp as admin. Its quite trivial application, hardest part is to figure out how to start command prompt at specific folder but google can help with that. Before using first solution that I found online I decided to take a look how Windows start it when you go with above mention method through File menu. It looks like MS uses undocumented trick, if you push path when starting cmd it will pop it and start in it. None of the solutions found on internet mention this way.



   /K     Run Command and then return to the CMD prompt.
          This is useful for testing, to examine variables
   /S    Strip " quote characters from command.
         If command starts with a quote, the first and last quote chars in command
         will be removed, whether /s is specified or not.

Source: http://ss64.com/nt/cmd.html

Pushd - Stores the name of the current directory for use by the popd command before changing the current directory to the specified directory.

Syntax: pushd [Path]

Source: https://technet.microsoft.com/en-us/library/bb490978.aspx


var p = new Process
    StartInfo =
        FileName = @"C:\Windows\system32\cmd.exe",
        UseShellExecute = true,
        Verb = "runas",
        Arguments = $"/s /k pushd \"{Directory.GetCurrentDirectory()}\" "


Application itself is done, but there is still one issue.

I have 64bit Windows and I want to start 64 bit cmd, if I compile with:

  1. Any CPU or x86 and run application, it will start 32bit cmd from C:\Windows\SysWOW64\cmd.exe
  2. x64 and run application, it will start 64bit cmd from C:\Windows\system32\cmd.exe

Cmd path doesn’t really matter, Windows does file redirection based on how app is compiled. More on that on MSDN.


Source and binaries

Check out my other projects
Active forks newsletter
Get a glimpse on open source active forks. Weekly newsletter with selection of repositories and their active forks.


Comments are closed