34

I would like to make a batch file that:

  1. Opens cmd.exe
  2. Within that Command Prompt runs net use to display mapped share paths
  3. Leaves the window open so that I can run additional commands if I wish to

How can I do this?

Gaff
  • 18,569
  • 15
  • 57
  • 68
AaronLS
  • 2,253
  • 4
  • 27
  • 27

1 Answers1

46

Put in your batch file

start cmd.exe /k "net use"

From cmd /?

Starts a new instance of the Windows XP command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string]

/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains

heavyd
  • 62,847
  • 18
  • 155
  • 177
  • 1
    I am not entirely sure why, but the batch file with that first line opened about 100 windows... – AaronLS Feb 09 '10 at 22:06
  • 17
    Oh, I know why, I named my batch file "net use.bat", and therefore cmd.exe tried to run "net use" and found the batch file first since it was the closest, therefore it was recursively running the batch file. LOL :() – AaronLS Feb 09 '10 at 22:09
  • 4
    @aaronls That is hilarious:) – phoebus Feb 09 '10 at 22:13
  • 1
    Sorry, should have been more specific. Perhaps you should use `net.exe use` next time... proof you can never assume anything. – heavyd Feb 09 '10 at 22:48
  • 3
    davr's "hilarious" batch file quickly brought my Win 7 machine to a halt. It wouldn't respond to Ctrl+Shift+Esc, Ctrl+Alt+Delete, Ctrl+Break etc. Make sure your documents are saved first. – Qwertie Mar 21 '12 at 23:47
  • If this ever does happen, you can right click on cmd.exe in Task Manager's Processes tab and click "End Process Tree". It will only end the ancestors of the one you click on though, not the descendants, so you may have to do this several times. – Andrew Jul 31 '17 at 12:17
  • 1
    Or even better: open a new Command Prompt and type, *without quotes*: "Tskill cmd" - this will close all Command Prompt windows. https://commandwindows.com/taskkill.htm – Andrew Jul 31 '17 at 12:21
  • i swapped the 'start' with 'call' command and the command executed in the same window. This was more preferred way for me. – Anmol Saraf Sep 26 '18 at 05:51