Wena Posted June 20, 2012 Posted June 20, 2012 (edited) Hi I want to stop services on a machine that has a user with no rights to do so. Is there a way of creating a script that would run as administrator from within itself. I know I could create another script and then use the RanAs() but then I would have 2 scripts. I could also use #RequireAdmin and the send down key strokes to simulate a input but this open to user interference. I have attached a sample script that I have done thus far.ShellStopStartServiceTest.au3 Edited June 21, 2012 by Wena
Moderators JLogan3o13 Posted June 20, 2012 Moderators Posted June 20, 2012 You could always try including the second script using the Resources UDF. That way it is not copied to the local machine but run completely from within the first executable. Something like this: All of your code above would go in your "Include" executable. #AutoIt3Wrapper_Res_File_Add=Include.exe, rt_rcdata, INCLUDE_EXE #include "resources.au3" _ResourceGetAsString("INCLUDE_EXE", "RT_RCDATA", 0, -1) RunAs($username, $domain, $pw, $flag, "INCLUDE_EXE") "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Wena Posted June 20, 2012 Author Posted June 20, 2012 Hi JLogan3o13I am sorry for the ignorance but I have no idea what your code does or mean.I tried seaching the help docs but cannot find any info on _ResourceGetAsString nor do I have an include file called resources.au3.Wena
Moderators JLogan3o13 Posted June 20, 2012 Moderators Posted June 20, 2012 (edited) Check out Zedna's great in the Examples forum section. Resources is an alternative to FileInstall; it allows you to include an external file (in this case your second script), but run it without having to first copy it to the local computer. If you find you are stuck using two scripts to accomplish what you would like, this may be a way to do it. Edited June 20, 2012 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
SlowCoder74 Posted June 20, 2012 Posted June 20, 2012 My method of mitigating this problem, if I understand correctly, is to: 1. Run script as non-elevated user 2. Prompt for elevated credentials. 3. Call the same script again with RunAs, and the elevated credentials, with "/STOPSERVICE" in the commandline. 4. Elevated script sees commandline and does what's needed. ... all as a single script.
Wena Posted June 21, 2012 Author Posted June 21, 2012 Hi Thanks for the help. @JLogin3o13--As a non programmer and a basic user of AutoIT your help was a bit over my head. I will however, in the near, future try make sense of it. @SlowCoder74---Reading your suggestion made me realize that thinking out the box is not always the best way. Simply got it working by using RanAs($usr, " ", $pwd, @comspec " /c" & "net start myservice") Thanks Wena
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now