Running a command as Administrator using PowerShell?

后端 未结 26 3396
粉色の甜心
粉色の甜心 2020-11-22 09:41

You know how if you\'re the administrative user of a system and you can just right click say, a batch script and run it as Administrator without entering the administrator p

26条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 10:01

    I have found a way to do this...

    Create a batch file to open your script:

    @echo off
    START "" "C:\Scripts\ScriptName.ps1"
    

    Then create a shortcut, on your desktop say (right click New -> Shortcut).

    Then paste this into the location:

    C:\Windows\System32\runas.exe /savecred /user:*DOMAIN*\*ADMIN USERNAME* C:\Scripts\BatchFileName.bat
    

    When first opening, you will have to enter your password once. This will then save it in the Windows credential manager.

    After this you should then be able to run as administrator without having to enter a administrator username or password.

提交回复
热议问题