Chizx
Chizx

Reputation: 349

Batch file to use cd without opening new window

I need to be able to type "asm" in cmd prompt and have it automatically switch to the c: drive and enter two directories. I wrote this in a batch file:

c:
cd \usr\masm
PAUSE

Then I used a bat-to-exe converter to create asm.exe, which I then moved to the C:\Windows\System32 folder so that I could execute the asm.bat file. Unfortunately, this opens a new command window, and the prompt then looks like this: Once you press enter the command window dissappears. I'm really new to creating and working with .bat files, how can I execute the .bat file in the cmd window already open without opening a new window, and how can I keep it open so that I can continue using the cmd prompt.

Any help greatly appreciated, thank you!

Upvotes: 0

Views: 453

Answers (2)

user4561223
user4561223

Reputation:

You should leave it as a .bat file, because you are not making an executable, you are making something you will run on an executable (cmd).

Upvotes: 2

Mike Wise
Mike Wise

Reputation: 22847

I think you need to leave it as a bat file. You should define a directory to put your bat files (like asm) in (like c:\bin or c:\bat) and change the path to include that directory. They you could enter the name of the bat file from anywhere and it would do what you want. When the bat file finished, it would simply leave you with the command prompt. If you move to a new machine, you can copy the directory and set the path on the other machine.

Upvotes: 1

Related Questions