none
How do I run Batch Files on Win 7 Pro?

    Question

  • Hi,

     

    I just got and installed Win 7. I can’t seem to run .bat files, even when I right click and run as administrator. You see the DOS window flash and that’s it. As simple test I just want to run a batch file that will restart my pc. If I remember correctly all you need to do is type “shutdown –r” in notepad. You then save it and change the extension to .bat.

     

    Please advise.
    Monday, April 12, 2010 8:16 PM

Answers

  • You're doing it the right way; you're just not seeing the results on the screen before the thing finishes and the window closes, and I suspect the command you're running is issuing an error.  To get that functionality, you could add a PAUSE command on a separate line.  For example, make a .bat file that contains these commands:

    The command you want here
    PAUSE

    The above will execute your command, then stop with a "Press any key to continue" message.  Before pressing any key, you'll be able to read any error messages emitted back to the command window by the execution of the prior command.

    Or you could open a CMD window, CD to the folder containing your batch file, and run it by typing its name.  You will see any errors that the command generates that way, and the window will not close.  The advantage to this, while developing your batch file, is that there is help on most of the commands available from within a CMD window...  For example, type shutdown /help at the command prompt.

    -Noel

     

    P.S., Please let me know if you need help finding the "any" key on the keyboard.  ;)  Just joking. :)

    • Proposed as answer by Noel Carboni Monday, April 12, 2010 8:33 PM
    • Marked as answer by Vivian Xing Thursday, April 22, 2010 8:32 AM
    Monday, April 12, 2010 8:33 PM
  • I run the shutdown /r bat file on local machine and a message appears saying that the computer will shut down in less than one minute. Please try Noel's suggestion to add the pause command and check if it works. If not, try it in Clean Boot mode.
    Vivian Xing - MSFT
    • Marked as answer by Vivian Xing Thursday, April 22, 2010 8:32 AM
    Wednesday, April 14, 2010 7:45 AM

All replies

  • KiFood schreef op 12-4-2010 22:16:

    > If I remember correctly all you need to do is type
    > “shutdown –r”

    Change that to "shutdown /r"

    --
    karelV [MVP - Windows Desktop Experience]
    Monday, April 12, 2010 8:32 PM
  • You're doing it the right way; you're just not seeing the results on the screen before the thing finishes and the window closes, and I suspect the command you're running is issuing an error.  To get that functionality, you could add a PAUSE command on a separate line.  For example, make a .bat file that contains these commands:

    The command you want here
    PAUSE

    The above will execute your command, then stop with a "Press any key to continue" message.  Before pressing any key, you'll be able to read any error messages emitted back to the command window by the execution of the prior command.

    Or you could open a CMD window, CD to the folder containing your batch file, and run it by typing its name.  You will see any errors that the command generates that way, and the window will not close.  The advantage to this, while developing your batch file, is that there is help on most of the commands available from within a CMD window...  For example, type shutdown /help at the command prompt.

    -Noel

     

    P.S., Please let me know if you need help finding the "any" key on the keyboard.  ;)  Just joking. :)

    • Proposed as answer by Noel Carboni Monday, April 12, 2010 8:33 PM
    • Marked as answer by Vivian Xing Thursday, April 22, 2010 8:32 AM
    Monday, April 12, 2010 8:33 PM
  • I run the shutdown /r bat file on local machine and a message appears saying that the computer will shut down in less than one minute. Please try Noel's suggestion to add the pause command and check if it works. If not, try it in Clean Boot mode.
    Vivian Xing - MSFT
    • Marked as answer by Vivian Xing Thursday, April 22, 2010 8:32 AM
    Wednesday, April 14, 2010 7:45 AM