Jump to content
Sign in to follow this  
Juvigy

[Resolved]Doing installation using elevated credentials

Recommended Posts

Juvigy

Can anyone help me with the part where the script would install (or do anything) as a different user where the user and the pass will be coded inside the script. Something like "runas" CMD command but with no password prompting the user.

!0x

Edited by Juvigy

Share this post


Link to post
Share on other sites
duckling78

The following will run your script as an administrator:

#RequireAdmin

Here's a paste from the help file:

#RequireAdmin

--------------------------------------------------------------------------------

Specifies that the current script requires full administrator rights to run.

#RequireAdmin

Parameters

None.

Remarks

This function was primarily aimed at allowing AutoIt scripts to work correctly with Windows Vista User Account Control (UAC) (However, will also work on Windows 2000 and Windows XP).

For more details see AutoIt on Windows Vista.

As this function launch a new process, some functions as Consolewrite() cannot be captured (Scite will not display anything).

Share this post


Link to post
Share on other sites
Juvigy

Require admin doesnt work for me. It just requires the user that runs the script to have admin rights.

I found that "RunAsSet" will do the trick , but it works only for the "run" functions. It wont work for the "ShellExecute" or other such functions. Is there any way that the whole script to have admin rights and not just the calls of the "run" functions?

Share this post


Link to post
Share on other sites
Distrophy

If not IsAdmin() Then
    RunAs("user","domain","pass",0,@ScriptName,@ScriptDir)
    Exit
EndIf

That will rerun your executable with credentials. I have only tested with executables but i dont think it will run the .au3.

Share this post


Link to post
Share on other sites
Juvigy

If not IsAdmin() Then
    RunAs("user","domain","pass",0,@ScriptName,@ScriptDir)
    Exit
EndIf

That will rerun your executable with credentials. I have only tested with executables but i dont think it will run the .au3.

I already found that , but it works only for "RunAs" function. I need more. For example ShellExecute or call dll's with admin credentials. And running the whole script/ ".exe" file with admin credentials / credentials i specify in the script.

Share this post


Link to post
Share on other sites
Distrophy

I already found that , but it works only for "RunAs" function. I need more. For example ShellExecute or call dll's with admin credentials. And running the whole script/ ".exe" file with admin credentials / credentials i specify in the script.

Right, you want to re-run your whole script as an admin if the current user isnt one, correct?

That code will do that. it is checking to see whether the current user is an admin, if they are not, the script re-runs itself using admin credentials.

the @ScriptName,@ScriptDir are telling autoit to rerun itself using the login provided.

I believe the code will only work once you have compiled your script to an exe.

Share this post


Link to post
Share on other sites
Juvigy

Cant find this functions in my AutoIt , or in the help file. I only find RunAsSet . I have V3 .

Share this post


Link to post
Share on other sites
TPlanet

Hi,

You have to run this script that will relaunch this script as admin, then do all you need;

CODE

If Not IsAdmin() Then

RunAsSet("Administrator",@ComputerName,"adminpassword")

FileCopy(@AutoItExe, "c:\TempInst\",8) ;if runned from network, need to copy the .exe on the wks as wks admin has't drive mapped

;make sure to copy it somewhere user has privileges to write and create folder

Runwait("c:\TempInst\" & @ScriptName , "c:\TempInst\")

DirRemove("c:\TempInst",1)

RunAsSet()

Exit

EndIf

; your code here, all will be runned as admin

ShellExecute()

run()

Exit

Have fun!

TP

Share this post


Link to post
Share on other sites
Jos

Cant find this functions in my AutoIt , or in the help file. I only find RunAsSet . I have V3 .

... use the latest AutoIt3 version for the RunAs(). RunAsSet() is obsolete since the latest release.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     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
jp10558

... use the latest AutoIt3 version for the RunAs(). RunAsSet() is obsolete since the latest release.

Jos

Was there any explanation why they changed from RunAsSet() to RunAs()? It seems to then make you type in the info many more times if you need to do several tasks as a different user.

Share this post


Link to post
Share on other sites
Juvigy

Thank you guys. It works perfectly now.

Share this post


Link to post
Share on other sites
jstump1

Sorry this reply is late -

Depending on what you are doing psexec (part of pstools from microsoft) may be useful for launching scripts with elevated priviledges.

It allows you to run the script against many hosts if necessary

It does not require that a user be logged on

It is a great tool to use in conjunction with AutoIT!

For requirements see:

http://forum.sysinternals.com/forum_posts....D=3748&PN=1

http://forum.sysinternals.com/forum_posts.asp?TID=9139

Stumppc

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  

×