locked
Batch file to run app with eleveated permissions RRS feed

  • Question

  • On a Windows 10 computer , domain users do not have local admin or domain admin privileges.

    I need run an application that needs to see the Mapped drives with " run as Admin"  the following command does not work since the mapped drives are not available and need to be mapped.

    C:\Windows\System32\runas.exe /savecred /user:DomainName\Adminuser C:\appfolder\app.exe

    The following steps work when done manually

    1. C:\Windows\System32\runas.exe /savecred /user:DomainName\Adminuser C:\Windows\System32\cmd.exe

    2. \\DCserver\netlogon\Login.bat

    3. C:\appfolder\app.exe

    However when I create a batch file  obviously a new CMD Window is opened and the the 2nd & 3rd commands are meaningless as they run in the original window.

    For now I have split it into two batch files. One batch file to open the CMD prompt with admin privileges. and another with 2 & 3 above. This works , but I need end users to follow this and I would rather have them run one batch file or even a power shell script if that works.

    Any and all advice is appreciated.

    Tuesday, October 1, 2019 4:44 PM

All replies

  • Hi, 

    Thank you for coming TechNet forum.

    As you encounter script issue, we would recommend to ask for help from Script forum. They should more familiar with such issue, and should have more resource to help you.

    Thank you for your understanding. 

    Script forum:

    https://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG

    Bests, 


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Proposed as answer by Joy-Qiao Wednesday, October 2, 2019 8:11 AM
    Wednesday, October 2, 2019 8:11 AM
  • Your first command line should use /C as a parameter to cmd.exe and then the path to another batch file to call the other two commands. e.g. Put this in a batch file on C: somewhere:

    @echo off
    call \\DCserver\netlogon\Login.bat
    start C:\appfolder\app.exe
    Then change your first step to this:
    C:\Windows\System32\runas.exe /savecred /user:DomainName\Adminuser C:\Windows\System32\cmd.exe /C C:\whatever.bat

    • Proposed as answer by Joy-Qiao Tuesday, October 8, 2019 8:02 AM
    Wednesday, October 2, 2019 8:49 AM
  • Hi,


    I am proposing previous helpful replies as "Answered". Please feel free to try it and let me know the result. If the reply is helpful, please remember to mark it as answer which can help other community members who have same questions and find the helpful reply quickly.

     

    Best regards,


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, October 8, 2019 8:02 AM