Jump to content
Sign in to follow this  
sheck

Execute Autoit Command as Admin

Recommended Posts

sheck

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
Paulie

RunAs()

?

Share this post


Link to post
Share on other sites
sheck

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
Richard Robertson

You can't.

Share this post


Link to post
Share on other sites
sheck

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
sheck

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
Paulie

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
sheck

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  

×