Suddenly can't run bat files as administrator

Page 1 of 2 12 LastLast

  1. Posts : 4
    Win10
       #1

    Suddenly can't run bat files as administrator


    New, weird, behavior --

    If I right click on a bat file, and Run as Administrator, all I get is a brief flash (perhaps a command window?).
    Just double clicking on it runs as expected (though not elevated, which is what I need).
    If I open an elevated command window and run the bat file within that window it works fine.

    So I have a workaround, but it's still annoying.
    It's always worked as expected in the past, I last used the batch files about a week ago.

    Tested with a simple bat file (echo "hello", pause). Same results.

    The fact that it is only a problem when I try Run as Administrator has me baffled.

    WIn10 Home build 10240, administrator user account
      My Computer


  2. Posts : 2,799
    Linux Mint 20.1 Win10Prox64
       #2

    How about using: echo "Hello" & pause
      My Computer


  3. Posts : 4
    Win10
    Thread Starter
       #3

    topgundcp said:
    How about using: echo "Hello" & pause
    Thanks, but that's irrelevant. I was just indicating that I had duplicated the problem with a simple batch file. (It actually had the commands on two lines).

    The contents of the batch file don't matter, the issue is that the "Run as Administrator" menu popup in Explorer no longer works properly.
      My Computer


  4. Posts : 569
    Windows 10 Pro/Windows 7 Ultimate
       #4

    Are you right-clicking on the file and running it "as administrator"? Because with Bat files, you should open a Command Prompt (Admin) By pressing Windows key+X, then after it is open, CD to the folder where the BAT files are, and then run it. That way, you can see if it ran or if it failed.
      My Computer


  5. Posts : 4
    Win10
    Thread Starter
       #5

    XweAponX said:
    Are you right-clicking on the file and running it "as administrator"? Because with Bat files, you should open a Command Prompt (Admin) By pressing Windows key+X, then after it is open, CD to the folder where the BAT files are, and then run it. That way, you can see if it ran or if it failed.
    Opening an elevated command prompt, as you describe, and as I mentioned, does work.
    Right-click, Run as Administrator no longer works. It used to.
    Running non-elevated, either by double-clicking or via opening a command prompt works (though then various commands fail due to lack of permission, as expected.)

    The weird thing is that right-click, Run as Administrator stopped working.
      My Computer


  6. Posts : 4
    Win10
    Thread Starter
       #6

    Well, I think I've got it, and it's definitely one of the more bizarre Microsoft bugs I've run into:

    The right-click, Run As Administrator function in File Explorer fails if the path to the target contains both an at sign (@) and a space.

    For example these paths work:
    D:\foo\bar\foobar\
    D:\foo\bar\foo bar\
    D:\@foo\bar\foobar\
    D:\@foo\bar@\foobar\

    But these prevent the target (batch file) from running:
    D:\@foo\bar\foo bar\
    D:\foo\bar\@foo bar\

    Or perhaps the actual bug is slightly different, but from the limited testing I performed, it's only the specific combination of @ and space, somewhere in the path, that causes failure. Other (non-reserved) special characters and unicode characters seem to work just fine.

    Weird.
    I'd love to hear an explanation, if anyone has one
      My Computer


  7. Posts : 9
    Windows 10 Pro
       #7

    Came across the exact same problem as CapnM on Windows 10 Pro 64-bit, where batch file does not "Run as Administrator" upon a right-click, but does from an elevated command prompt. But I don't think his suggestion applies to this .bat script that deletes OneDrive:

    taskkill /f /im OneDrive.exe
    %SystemRoot%\SysWOW64\OneDriveSetup.exe /uninstall
    rd "%UserProfile%\OneDrive" /Q /S
    rd "%LocalAppData%\Microsoft\OneDrive" /Q /S
    rd "%ProgramData%\Microsoft OneDrive" /Q /S
    rd "C:\OneDriveTemp" /Q /S
    REG Delete "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
    REG Delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
    pause

    Additional suggestions, or ideas welcome.
      My Computer


  8. Posts : 42,734
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #8

    Hi, does 'Run as admin' work on anything?

    Users who have had problems with this have found there's another shell extension present, which, when disabled, magically allows Run as admin to work again.

    Try disabling other (non-MS) context menu entries using
    Shellexview
    Shellmenu
    (free)

    Remember to make sure MS entries are hidden in Options (they should be by default) as disabling them can cause difficulty.

    Two recent examples were
    winrar and something like quicksfv
      My Computers


  9. Posts : 9
    Windows 10 Pro
       #9

    I got my old scripts to work. I moved them to the root level directory on C:\ All is back to normal.
      My Computer


  10. Posts : 1
    win10pro/win10home
       #10

    This was my experience too...


    Same as above . . . I tried to Run As Administrator from context menu on a bat file. (not a cmd file). Did not work when the file was on the desktop, just a dialog flash and disappear as op said. Moved file to root of c:, ran same command same way, worked fine. Anyone have any ideas or answers? Permissions issue? Running Win10Home x64
      My Computer


 

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

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




Windows 10 Forums