Sign in to follow this  
Followers 0
Muscle

run exe with saved admin rights

13 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

thx jos! but the problem is that id doesn´t work ( i already tried). i have the newest autoit version (3.2.12.1)

muscle

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Now did you open that helpfile and check the syntax ?

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

of course i did!

i used: RunAs($run_admin_user, @ComputerName, $run_admin_pass, 0, @ComSpec)

but then only 2 cmd windows open and that´s all

muscle

Share this post


Link to post
Share on other sites

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

Just specify the proigram you want to execute.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

then i use the script name it always restarts it self and nothing is happing.

muscle

Share this post


Link to post
Share on other sites

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

yeah something like this - but it´s not working (the scripts closes itself) :-(

muscle

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

thx, i will try it direct

muscle

Share this post


Link to post
Share on other sites

then i run it, i get a INVALID CMDLINE - Error

???

muscle

Share this post


Link to post
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
Sign in to follow this  
Followers 0