Jump to content

Recommended Posts

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
  • Developers
Posted

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.
  :)

Posted

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

  • Developers
Posted

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.
  :)

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

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
  • Recently Browsing   0 members

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