Bat file running as administrator does not work


  1. Posts : 13
    Windows 7 Home Premium 64bit
       #1

    Bat file running as administrator does not work


    Here is my test bat file:
    @echo off
    echo\
    echo "Hello David"
    echo\
    pause

    If I run this very simple bat file in a user account or admin account, or in an elevated command window, it works fine - I see the text and the pause - no errors. But if I run the bat file as Administrator (mouse right click) or use a shortcut to the bat file that runs as administrator, the window appears and immediately disappears. I do not see the text or the pause. Why? What am I missing?
      My Computer


  2. Posts : 72,049
    64-bit Windows 11 Pro for Workstations
       #2

    Hello David,

    It may be an issue with the registry for "Run as administrator". If you like as a test, use step 2 in the tutorial below to restore "Run as administrator" to the context menu. This will also restore the default registry entries for it, and hopefully allow it to run properly afterwards. :)

    Run as Administrator - Add or Remove from Context Menu in Windows 7
      My Computer


  3. Posts : 1
    Windows 7
       #3

    I found the answer to this very annoying issue in my case was simply that the name of my batch file contained an Ampersand ("&") and Windows 10 (and Windows 7) for some reason do not like having this character in the file name when combined with the "Run as Administrator" option - either from the right-click context menu, or ticked in the icon. Stupid, really, since everywhere else an Ampersand seems to be a valid character for a file name....

    Thus the reason that "Pause" didn't work was because it never even opened the file to begin running commands.
      My Computer


  4. Posts : 3,615
    Win 10 x64, Linux Lite, Win 7 x64, BlackArch, & Kali
       #4

    Excellent troubleshooting MiTuCents

    Please mark this thread as resolved.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 23:55.
Find Us