Sign in to follow this  
Followers 0
sheck

Execute Autoit Command as Admin

9 posts in this topic

I was wondering if it's possible to execute a command as a different user inside AutoIt without restarting script ?

For example if I start script as a normal user in XP, but want to run some commands inside that script as Admin without running the whole script as Admin.


Live and Learn, 'cause Knowledge is Super Power.

Share this post


Link to post
Share on other sites



RunAs()

?

Share this post


Link to post
Share on other sites

RunAs()

?

According to documentation RunAs() only executes files (EXE, BAT, COM, or PIF). I need to run a command such as FileDelete("").

How can I do that ?


Live and Learn, 'cause Knowledge is Super Power.

Share this post


Link to post
Share on other sites

You can't.

Share this post


Link to post
Share on other sites

You can't.

That's a shame. Oh well, I will have to go around it.


Live and Learn, 'cause Knowledge is Super Power.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Isn't that exactly what #RequireAdmin does?

No, that just tells Windows that this script can be executed only by someone with Admin Rights.

Edited by sheckandar

Live and Learn, 'cause Knowledge is Super Power.

Share this post


Link to post
Share on other sites

Well, you could always do it with command prompt i think, i've never tried this

$Path = @DesktopDir&"\foo.txt"
RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c " & 'del "'&$Path&'"', @SystemDir, @SW_HIDE)

Share this post


Link to post
Share on other sites

Well, you could always do it with command prompt i think, i've never tried this

$Path = @DesktopDir&"\foo.txt"
RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c " & 'del "'&$Path&'"', @SystemDir, @SW_HIDE)
Yes you can, however I would like not to do it that way, because not all commands can be read with STDOUR_READ() and I need to know exit code.

Live and Learn, 'cause Knowledge is Super Power.

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