Jump to content

run exe with saved admin rights


Muscle
 Share

Recommended Posts

hi @ all!!!

i have a big problem. i wrote a script that needs admin rights on vista and xp.

the problem is that i want to run the script with admin rights which are saved

in a ini file. Then you can run the script on an account without admin rights

with the saved user login data.

Can anyone help me to realize that? I had an old script (i don´t know from where xD)

that worked really good on xp - but it was an very old autoit version.

Thanks!!!!!

Muscle

adminrights()

Func adminrights()
    If Not IsAdmin() Then
        Opt("RunErrorsFatal", 0)    
        
; Admin-Account user
        $run_admin_user = IniRead("data.ini", "Data", "account-user", "-")

; Admin-Account pass
        $run_admin_pass = IniRead("data.ini", "Data", "account-pass", "-")

; adminrights
        If Not $CMDLINE[0] Then
            RunAsSet($run_admin_user, @ComputerName, $run_admin_pass)
            Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /admin')
            If @error = 1 Then
                MsgBox(48, "-", "Error")
            Else
                RunAsSet()
            EndIf
            Exit
        ElseIf $CMDLINE[1] <> '/admin' Then
            MsgBox(48, "-", "Error")
            Exit 1
        EndIf
    EndIf
EndFunc

If IsAdmin() Then MsgBox(0, "", "NOW adminrights")
Edited by Muscle
Link to comment
Share on other sites

  • Developers

Check the Helpfile that came with the version you use now to see if you have a resent version of AutoIt3 that has a new syntax for running programs under different credentions.. it is now RunAs()

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

sounds logical when you run the script shown....

Now did you open that helpfile and check the syntax ?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

You have defined @comspec there so that is what it runs -> the CMD.EXE.

Just specify the proigram you want to execute.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

I assume you want something like this (untested):

Func adminrights()
    If Not IsAdmin() Then
    ; Admin-Account user
        $run_admin_user = IniRead("data.ini", "Data", "account-user", "-")
    ; Admin-Account pass
        $run_admin_pass = IniRead("data.ini", "Data", "account-pass", "-")
    ; adminrights
        If Not $CMDLINE[0] Then
            RunAs($run_admin_user, @ComputerName, $run_admin_pass, 0,'"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /admin')
            If @error = 1 Then
                MsgBox(48, "-", "Error")
            EndIf
            Exit
        ElseIf $CMDLINE[1] <> '/admin' Then
            MsgBox(48, "-", "Error")
            Exit 1
        EndIf
    EndIf
EndFunc  ;==>adminrights

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

adminrights()

Func adminrights()
    If Not IsAdmin() Then
   ; Admin-Account user
        $run_admin_user = "Blub"
   ; Admin-Account pass
        $run_admin_pass = "test"
   ; adminrights
        If Not $CMDLINE[0] Then
            RunAs($run_admin_user, @ComputerName, $run_admin_pass, 0,'"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /admin')
            If @error = 1 Then
                MsgBox(48, "-", "Error")
            EndIf
            Exit
        ElseIf $CMDLINE[1] <> '/admin' Then
            MsgBox(48, "-", "Error")
            Exit 1
        EndIf
    EndIf
EndFunc ;==>adminrights

If IsAdmin() Then MsgBox(0, "", "NOW adminrights")

muscle

Edited by Muscle
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...