Jump to content

[Question] Is It Possible To Run A Program As A Different User With AutoIt?


Recommended Posts

Hello.. AutoIt Team.. I Was Wondering Is It Possible To Run A Program As A Different User.. Using AutoIt..? If So..

Can Someone Help Me.. Like Post A Little Example Script.. :) But If Not Then Just Tell Me And Close The Post.

Thanks ~

- John

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

AutoItv3 Rocks <3! ^_^

Edited by John2006

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

Function Reference

RunAsSet

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

Initialise a set of user credentials to use during Run and RunWait operations. 2000/XP or later ONLY.

RunAsSet ( ["user", "domain", "password" [, options]] )

Parameters

username [optional] The user name to use.

domain [optional] The domain name to use.

password [optional] The password to use.

options [optional] 0 = do not load the user profile, 1 = (default) load the user profile, 2 = use for net credentials only

Return Value

Success: Returns 1--regardless of success. (If the login information was invalid, subsequent Run/RunWait commands will fail....)

Failure: Returns 0 if the operating system does not support this function.

Remarks

This function allows subsequent Run and RunWait functions to run as a different user (e.g. Administrator). The function only works on the 2000/XP (or later) platforms. NT4 users should install and use the SU command from the NT Resource Kit.

The "Secondary Logon service" or "RunAs service" must not be disabled if you want this function to work.

To unset the RunAs details, use the function with no parameters: RunAsSet().

Related

Run, RunErrorsFatal (Option), RunWait

Example


; This example will rerun itself with admin rights on using a local account
; Note on Vista this may not work as even though the user is admin it may 
; not be elevated even after the RunAs call.  In that case use #RequireAdmin
; at the top of the script.

; Are we already admin?
If Not IsAdmin() Then
    RunAsSet('USER', @Computername, 'PASSWORD')
    Run('"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir)
    Exit
EndIf

MsgBox(0, 'Message', 'Now running with admin rights.')
Link to comment
Share on other sites

@Nevin. Wouldn't it have been more efficient just to paste a link to the online documentation instead of copying and pasting the exact text from the help file into the post. ;-)

http://www.autoitscript.com/autoit3/docs/f...ns/RunAsSet.htm

I'm just messing with you. ;-)

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

@Nevin. Wouldn't it have been more efficient just to paste a link to the online documentation instead of copying and pasting the exact text from the help file into the post. ;-)

This is precisely why my post contained no more text than the function name. I don't really see the need of wasting time/space copying the documentation and if the documentation isn't good enough for the user to understand how to use the function, then we need to know that so it can be made easier to understand.
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...