Jump to content

RunAs


Recommended Posts

@AdamUL

I have no words to thank you, I'm struggling for a long time for a solution to this problem.

The closest I got is use runasspc, but it flashes a terminal every time it run, and popup a window with license info at random intervals.

Your solution works like a charm.

Some programs like coretemp don't run under restricted account, with your script I can launch It at login like it should.

Link to comment
Share on other sites

  • 1 year later...

Hi,

I tried using this script for the same exact reason as jsnyder213 however it's not working for me.

I get "ERROR!", "Unable to run under administrator account."

 

Global $sAdminUser = "admin"
Global $sAdminPassword = "password"
Global $sDomain = @ComputerName
Global $iLogOnFlag = 0
Global $sParameters = ""

;Elevate with the Admin account.
If @UserName <> $sAdminUser And Not IsAdmin() Then
    $sParameters = ""
    If Not @Compiled Then
        $sParameters = ' "' & @ScriptFullPath & '"'
    EndIf

    If RunAs($sAdminUser, $sDomain, $sAdminPassword, $iLogOnFlag, @AutoItExe & $sParameters) Then
        Exit
    Else
        Exit MsgBox(16 + 262144, "ERROR!", "Unable to run under administrator account.")
    EndIf
EndIf

;Run with Admin Token in Windows Vista and Higher.
If @UserName = $sAdminUser And Not IsAdmin() And Not StringRegExp(@OSVersion, "_(XP|200(0|3))") Then
    $sParameters = ""
    If Not @Compiled Then
        $sParameters = '"' & @ScriptFullPath & '"'
    EndIf

    If ShellExecute(@AutoItExe, $sParameters, "", "runas") Then
        Exit
    Else
        Exit MsgBox(16 + 262144, "ERROR!", "Unable to elevate to Admin due to UAC.")
    EndIf
EndIf

;Put rest of the script here.

Run(@ScriptDir & "\sw2016.exe")

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...