Jump to content

Running script with admin rights


Recommended Posts

Here is my problem I got this piece of code from the forums a while back and it has worked flawlessly until I upgraded to v3.2.12.0. Here is the script...(I apologize that I can not credit the original poster of this snippet)

if Not IsAdmin() Then
    RunAsSet(<user name would be here>, @Computername, <user password would be here>)
    Run('"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir)
    Exit
EndIf

This would basically restart the script using admin rights. Is there anyway to get this same process under the new version?

I know I could use runonce and logoff and log back in as ADMIN then once the script is run logoff again and logon as limited user, that just takes all the fun away :)

Link to comment
Share on other sites

I haven't tested this, but give it a shot. :)

If Not IsAdmin() Then
    RunAs($username, @computername, $password, 4, '"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir)
    Exit
EndIf
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

Hello,

see here : http://www.autoitscript.com/autoit3/docs/history.htm

Removed: RunAsSet(). (Replaced with RunAs() and RunAsWait())

And therein lies my problem. The snippet I provided uses RunAsSet but replacing it with just RunAs in that code does not work. I'm hoping maybe the original poster of the snippet will see it (or someone who has a bit more experience than me which would probably be just about anyone :) ) and have come up with a way around it.

But thanks for the response just the same.

Link to comment
Share on other sites

And therein lies my problem. The snippet I provided uses RunAsSet but replacing it with just RunAs in that code does not work. I'm hoping maybe the original poster of the snippet will see it (or someone who has a bit more experience than me which would probably be just about anyone :) ) and have come up with a way around it.

But thanks for the response just the same.

Try to replace the 4 in my example with 1 through 3... I'm guessing it has something to do with the way the profile is loaded. RunAs is just a conjunction of RunAsSet and Run. Edited by Airwolf123
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

Try to replace the 4 in my example with 1 through 3... I'm guessing it has something to do with the way the profile is loaded. RunAs is just a conjunction of RunAsSet and Run.

Nope just tried it. The problem seems to be the script isn't reloading. In the original snippet, as far as I understand it, the script is called via Run under admin rights (basically another instance is started) then the original script is stopped. Elegant in it's simplicity but a bugger now!!!

I guess I could have another script call the script I need run using RunAsWait once the called script is run kill the calling script, or just kill it to begin with by using RunAs, but that is just not as fun :)

Thanks for the help thus far

Link to comment
Share on other sites

What's the value of @error after the call to RunAs?

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

@error returns a 1. So what does that mean? should I be seeing a new instant of the program running?

I'm so confused :)

Per the description of the RunAs function in the AutoIt3 help file, a value of anything but zero in @error means that there was an error running the command line. I don't think it's documented in the help file, but @extended should have the Windows error code describing what the problem was.

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

It may be running under the user's profile of which you are using credentials for. Do you see anything running under Processes in Task Manager for the user?

Nope, nada, zip -

Did get it to continually loop that was fun to break out of!!! Put the run command from the snippet after your original idea. The bugger just kept restarting the script ad neausium :) But never getting admin rights!!! :)

Link to comment
Share on other sites

Per the description of the RunAs function in the AutoIt3 help file, a value of anything but zero in @error means that there was an error running the command line. I don't think it's documented in the help file, but @extended should have the Windows error code describing what the problem was.

I see what you are saying. Missed that in speed reading the help file!!! :)

Well I'm off to home will see what results I get tomorrow.

Thanks for all the replies so far. Guess this is a bit more involved that I thought.

[edit]

Okay I got a windows error code of 1314 and looking that up I see it is

ERROR_PRIVILEGE_NOT_HELD

1314

0x522

A required privilege is not held by the client.

So does this mean that windows RunAs service is not functional on my system? Seems to be the case! updating to service pack 4 (not sure if this was done or not) will see what the outcome of that is.

[edit again]

Updated to SP4 and RUNAS windows command worked (may have worked before but I was not paying attention) but RunAs under autoit still returning same error stated above.

Edited by Bowian
Link to comment
Share on other sites

[edit]

Okay I got a windows error code of 1314 and looking that up I see it is

ERROR_PRIVILEGE_NOT_HELD

1314

0x522

A required privilege is not held by the client.

So does this mean that windows RunAs service is not functional on my system? Seems to be the case! updating to service pack 4 (not sure if this was done or not) will see what the outcome of that is.

For now I will just use CPAU as the calling program. Deadlines loom large...

Thanks for all the help on this issue.

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