3

I'm working with a program that requires me to open a command-line window in the directory containing the some files. The issue I face is that Windows has since removed the option from the context menu top open CMD in a given location. I want to know how I can make a batch script run this option when executed in a given folder or location (i.e. where the script is located). I know I can run cmd with this code:

%SystemRoot%\System32\cmd.exe pause

Using this script does not appear to function the same way. I should be getting some other information in the command window according to the documentation.

6
  • You can open the terminal THEN navigate to the desired folder.
    – user772515
    Sep 22, 2017 at 4:43
  • How? I only know how to navigate to a DOS executable. Do I just enter the path in the console? Sep 22, 2017 at 4:45
  • 1
    digitalcitizen.life/command-prompt-how-use-basic-commands
    – user772515
    Sep 22, 2017 at 4:46
  • 1
    If you Shift + right click, 'Open Powershell' should be an option. Click that, then type cmd. This should run command prompt in that folder within the Powershell window. Sep 22, 2017 at 5:12
  • 1
    the cd command might help like cd \windows you might be able to use this in a shortcut or batch file start c:\windows\system32\cmd.exe /k "cd \windows" or just from a cmd prompt or a batch file do cd \windows
    – barlop
    Sep 22, 2017 at 6:47

2 Answers 2

4

As I understand, you want a batch file that opens a CMD in the folder where it is located itself?

Add this lines in a file with file extension .bat.

pushd %~dp0
cmd.exe

After doubleclick you have a CMD window opened in the folder where the file is located.

1
  • Excellent work! This functions precisley as I wanted. If I post this work-around on the tutorial thread, I'll be sure to credit everyone that helped make this possible. Sep 22, 2017 at 8:30
1

Usually these batch files are written pretty poorly, and I make a habit of re-writing them for the hell of it whenever I root a phone.

That said you can open a CMD "Here" in windows 8.1/10 2012(R2)

To do that click "File" and click "Open Command Prompt" and select if you want a regular otr admin prompt (you can also right click on this and add it to the quick-access bar)

Opening CMD "Here" in Explorer - Example using Windows 2012R2, works in Windows 8.1 and forward.

Otherwise you can use this code in a batch file:

start /D "%~dp1" cmd 

This will allow you to drag and drop a file or folder onto the cmd file and it will start the cmd window in the directory of the file or folder.

If you want to make the CMD window start in the same directory as some script that you just want to add this line to, then you would use 0 instead of 1.

REM Some code in your current script

start /D "%~dp0" cmd 

REM some code that will execute after the new CMD window is popped up for you.
2
  • 1
    Thank you, I will add this script method to my archives. Sep 27, 2017 at 4:54
  • You're welcome, glad to help :) Sep 28, 2017 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .