running DOS as ADMIN

Page 1 of 11 123 ... LastLast

  1. Posts : 245
    windows 10
       #1

    running DOS as ADMIN


    I need to run a command (schtasks) that requires ADMIN privileges. I added schtasks to a bat file (along with my other DOS commands that do not require ADMIN priviliges), right-clicked its shortcut and chose the
    RUN AS ADMIN
    option. A DOS screen appeared for a milisecond and then vanished so I have no idea what the problem is (since without running as ADMIN the DOS screen remains for me to take further action).

    I can run other programs as ADMIN so why can't I run this one? For example, if I were to open a DOS window as ADMIN and then manually type in the schtasks command there would be no problem.

    Thanks in advance to all who reply.
    Dan
      My Computer


  2. Posts : 31,471
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #2

    bromberg said:
    ...I added schtasks to a bat file... right-clicked its shortcut and chose the RUN AS ADMIN option. A DOS screen appeared for a milisecond and then vanished so I have no idea what the problem is...
    Two things you can do to help you debug this.

    The first is to right-click on the shortcut to the .bat file, select Properties and click the Advanced button on the Shortcut tab. Here you can set it to always run as an administrator when you launch it from the shortcut.

    The second is to add the command PAUSE to the .bat file (as the last line or immediately after the schtasks command) so that it doesn't close immediately it has executed. That will allow you to read any error messages.
      My Computers


  3. Posts : 245
    windows 10
    Thread Starter
       #3

    Bree said:
    Two things you can do to help you debug this.

    The first is to right-click on the shortcut to the .bat file, select Properties and click the Advanced button on the Shortcut tab. Here you can set it to always run as an administrator when you launch it from the shortcut.

    The second is to add the command PAUSE to the .bat file (as the last line or immediately after the schtasks command) so that it doesn't close immediately it has executed. That will allow you to read any error messages.
    Bree,
    I had already tried both of your suggestions prior to opening this issue and in each case the DOS window quickly disappears.
    Does Windows keep a record of why it fails (like the EventViewer or somewhere else?).
    Thanks,
    Dan
      My Computer


  4. Posts : 31,471
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #4

    bromberg said:
    Does Windows keep a record of why it fails (like the EventViewer or somewhere else?).
    That would depend on why it failed. An actual crash may well be recorded in the event log, but a misconfigured shortcut or .bat file may well not. Have you looked in the Event Log yet?

    I've tried to reproduce your problem with a test .bat file containing a few commands including a schtasks one. I created it on the desktop then created a shortcut to it. Whatever I try I cannot get it to fail.

    The only way I can reproduce what you describe (a DOS screen appeared for a milisecond and then vanished) is to have a shortcut to a .bat file with no commands in it. Check your shortcut is pointing to the correct file. If you right-click on the shortcut and select Edit does it open the correct .bat file in Notepad?

    If the shortcut is correct, then one other thing you could try to debug this .bat is to open a Command Prompt (Admin), CD into the folder containing the .bat file then type its name. That will run the .bat file in a window that will remain open after it completes (or fails).
      My Computers


  5. Posts : 245
    windows 10
    Thread Starter
       #5

    When I run this command
    schtasks /run /i /tn "\Microsoft\Windows\Registry\RegIdleBackup"
    in an ADMIN DOS window it runs successfully.

    However when I put this command into a bat file it fails (DOS window disappears immediately) when:
    1) I double-click it *OR*
    2) right-click and choose the RUN AS ADMIN option

    I don't know why you cannot reproduce it. I imagine you have your system set up with additional priviliges.
    Since I'm the only user of my PC I wish I knew how to set up my PC like yours so I wouldn't have this problem.

    But thanks for the right-click EDIT tip. I was renaming my 'bat' extension to 'txt' so I could open without running, so your way is much better!
    And yes, my shortcut (with the ADVANCED|RUN AS ADMIN) does point to my bat file.
      My Computer


  6. Posts : 31,471
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #6

    bromberg said:
    ...when I put this command into a bat file it fails (DOS window disappears immediately) ... I don't know why you cannot reproduce it. I imagine you have your system set up with additional priviliges..

    Ah, now we're getting somewhere. That was indeed the command I used in my test. But crucially, even in Task Scheduler, by default you are not allowed to run that RegIdleBackup task on demand. I was testing on a machine where I had enabled that task to be run manually. You need to enable it in the registry editor and restart the PC, then your .bat will run. See...

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Configuration Manager
    EnablePeriodicBackup DWORD
    (delete) = Disable
    1 = Enable
    Enable Automatic Backup of System Registry when Restart in Windows 10
      My Computers


  7. Posts : 245
    windows 10
    Thread Starter
       #7

    Bree said:
    Ah, now we're getting somewhere. That was indeed the command I used in my test. But crucially, even in Task Scheduler, by default you are not allowed to run that RegIdleBackup task on demand. I was testing on a machine where I had enabled that task to be run manually. You need to enable it in the registry editor and restart the PC, then your .bat will run. See...

    Enable Automatic Backup of System Registry when Restart in Windows 10

    But I did successfully run the RegIdleBackup task from the Task Scheduler, so I'm unsure why you say I cannot. A few days ago I learned about adding the EnablePeriodicBackup dword and setting it to 1. I then ENABLED the RegIdleBackup task and clicked on RUN and it did make a backup copy of my Registry in REGBACK.
    So I know how to do it from the Task Scheduler which is cumbersome and is why I want to do it from a bat file containing the shutdown (and other) commands that I issue just before ending my PC session.
      My Computer


  8. Posts : 31,471
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #8

    Well, if I create the EnablePeriodicBackup DWORD in the registry and set it to 1 I can run that .bat file, If I delete it I can't.

    The only thing I can think of is have you restarted? It does require a restart for the change to take effect after you add that DWORD.
      My Computers


  9. Posts : 16,784
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #9

    Some suggestions -

    1 You have not mentioned it but I assume that after you run the shortcut with RunAs Admin, your Admin prompt appears as expected and you are able to give permission to proceed.

    2 Add a Pause command as a first line so you can check that the batch file actually starts.

    3 If there were multiple command lines in the batch file I'd also suggest progressively moving the Pause line down until the problem reoccurs. If I have understood you correctly, there is only one command line in the batch file so this is not relvant.

    4 Remove all the Pause lines & alter the shortcut to force it to give you a log of what happens.
    - Alter the Target field of the shortcut's properties
    - Keep the shortcut as RunAs Admin
    - Put in a path & batch file name and put in a path & log name for the output that makes sense for you instead of my examples
    Code:
    C:\Tools\MyRegBackup.bat >D:\Desktop\MyRegBackup.Log
    - This can very often reveal the cause of a batch file failure so I hope it does in your case.

    Best of luck,
    Denis
      My Computer


  10. Posts : 245
    windows 10
    Thread Starter
       #10

    Try3 said:
    Some suggestions -

    1 You have not mentioned it but I assume that after you run the shortcut with RunAs Admin, your Admin prompt appears as expected and you are able to give permission to proceed.

    2 Add a Pause command as a first line so you can check that the batch file actually starts.

    3 If there were multiple command lines in the batch file I'd also suggest progressively moving the Pause line down until the problem reoccurs. If I have understood you correctly, there is only one command line in the batch file so this is not relvant.

    4 Remove all the Pause lines & alter the shortcut to force it to give you a log of what happens.
    - Alter the Target field of the shortcut's properties
    - Keep the shortcut as RunAs Admin
    - Put in a path & batch file name and put in a path & log name for the output that makes sense for you instead of my examples
    Code:
    C:\Tools\MyRegBackup.bat >D:\Desktop\MyRegBackup.Log
    - This can very often reveal the cause of a batch file failure so I hope it does in your case.

    Best of luck,
    Denis
    Denis,
    Yes, I did RUN AS ADMIN and use PAUSE when needed but all to no avail.
    What is your "TOOLS" directory all about?
    Thanks,
    Dan
      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 18:55.
Find Us




Windows 10 Forums