Sign in to follow this  
Followers 0
abhi

Impersonating Windows Run As

8 posts in this topic

Hello,

I have a gui that accepts userid,password and commands (that need to be executed in a text area)

I redirect the commands to a .bat file and I want to execute them using the credentials I have got from the user. How can I achieve the same using autoit?

Any help is highly appreciated.

Thanks

Share this post


Link to post
Share on other sites



the funtion RunAs()...


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Edited by Volly

Share this post


Link to post
Share on other sites

Volly,

I was considering the RunAsSet() call but I am not sure how I'd passing the actual cmd that needs to be executed

Assuming $var contains my cmd, I do not see how I could pass it along to RunAsSet().

Thanks

:">

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

Share this post


Link to post
Share on other sites

its explained in volly's post (remarks) but maybe you need an example :whistle:

; Set the RunAs parameters to use local adminstrator account
RunAsSet("Administrator", @Computername, "adminpassword")

; Run registry editor as admin
RunWait("regedit.exe")

; Reset user's permissions
RunAsSet()

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

Share this post


Link to post
Share on other sites

pardon my ignorance, but an exampl will definitely help

its explained in volly's post (remarks) but maybe you need an example :whistle:

; Set the RunAs parameters to use local adminstrator account
RunAsSet("Administrator", @Computername, "adminpassword")

; Run registry editor as admin
RunWait("regedit.exe")

; Reset user's permissions
RunAsSet()

Share this post


Link to post
Share on other sites

Got it!

Thanks

its explained in volly's post (remarks) but maybe you need an example :whistle:

; Set the RunAs parameters to use local adminstrator account
RunAsSet("Administrator", @Computername, "adminpassword")

; Run registry editor as admin
RunWait("regedit.exe")

; Reset user's permissions
RunAsSet()

Share this post


Link to post
Share on other sites

pardon my ignorance, but an exampl will definitely help

He just gave you one.

In his example 3 things happen

1) The RunAsSet command is used to initiate rights of "Administrator"

2) the run command is used to perform an action (while you are using the "Administrator" account's rights)

3) The RunAsSet command is then run again (without parameters) to release the "Administators" permissons


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

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