akorx Posted February 3, 2012 Share Posted February 3, 2012 (edited) Hi Guys,Few versions ago there was the RusAsSet function that has now disappered... now : how can i do to run a function (not a external program but a autoit function like regwrite) with admin rights ?I've tried this but it doesn' t work :$cmd1="RegWrite(" & "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesUSBSTOR" & "," & "start" & "," & "REG_DWORD" & ",0x00000003)";MsgBox(4096,"test",$cmd1)RunAs("Administrateur","********","********",0,$cmd1)Exit=> don't forget to change "administrateur" by "administrator" if you are using an english version of XP !NB : sorry for my bad english, i'm french Edited February 3, 2012 by akorx AkorxMail akorx@yahoo.fr Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 3, 2012 Moderators Share Posted February 3, 2012 Hi, akorx. Check out RunAs and #RequireAdmin in the help file. "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! Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted February 3, 2012 Share Posted February 3, 2012 RusAsSet() never did anything like that, it did what RunAs()/RunAsWait() do now. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
akorx Posted February 3, 2012 Author Share Posted February 3, 2012 (edited) Thx guys for your help... so try to use my script and see what happens : nothing !!! There is something that i don't understand : every commands in autoit are written in bold... but when i'm writting "rusas" this command stays "unbold" ("unbold" is the good word ? i don't know if it's an english term...). Why ? Edited February 3, 2012 by akorx AkorxMail akorx@yahoo.fr Link to comment Share on other sites More sharing options...
Chimaera Posted February 3, 2012 Share Posted February 3, 2012 (edited) Probably because Rusas does'nt exist as a valid command now, i dont know if it did before. I checked on my autoit and if you type it nothing shows when you reach Rus. Admiral With hat has given you the commands earlier, and check the help file for refernce. If you have a very old script you may have to update the commands to the modern versions Edit typo Edited February 3, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2012 Moderators Share Posted February 3, 2012 akorx, What version of AutoIt are you using? If you do not know run this line in SciTE: ConsoleWrite(@AutoItVersion & @CRLF) and tell us what is returned in the lower pane. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
akorx Posted February 3, 2012 Author Share Posted February 3, 2012 (edited) I've got the last version (3.3.8.1) and my script is a new one. If i'm starting to write "run", Scite answer :run / runas / runaswait / runwait so "runas" exists ! I dont't understand why it's not bold... but it's not the problem, the actual problem is "how run an autoit function with admin rights ?" ! Edited February 3, 2012 by akorx AkorxMail akorx@yahoo.fr Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 3, 2012 Moderators Share Posted February 3, 2012 But you stated in your previous post you typed in Rusas, not RunAs. There is no Rusas. "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! Link to comment Share on other sites More sharing options...
Guest Posted February 3, 2012 Share Posted February 3, 2012 Thx guys for your help... so try to use my script and see what happens : nothing !!!There is something that i don't understand : every commands in autoit are written in bold... but when i'm writting "rusas" this command stays "unbold" ("unbold" is the good word ? i don't know if it's an english term...).Why ?It is "RunAs" Not "rusas" Link to comment Share on other sites More sharing options...
Mikeman27294 Posted February 3, 2012 Share Posted February 3, 2012 (edited) I've got the last version (3.3.8.1) and my script is a new one.If i'm starting to write "run", Scite answer :run / runas / runaswait / runwait so "runas" exists !I dont't understand why it's not bold... but it's not the problem, the actual problem is "how run an autoit function with admin rights ?" !http://www.autoitscript.com/autoit3/docs/functions/RunAs.htmScite isn't nearly as helpful as the help file. Press F1 when you are using scite. The help file should be your best friend. It will not allow you to run a function, but it will allow you to run a script. If you want to run a function with admin status, I reccommend you use paramaters. For example, you use the parameter -a to have the program run the function. If you don't understand how to do this, I will attach some code in a minute. Edited February 3, 2012 by Mikeman27294 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2012 Moderators Share Posted February 3, 2012 akorx,I know RunAs exists. If you type " RunAs(" into your script, do you get the CallTip (the list of parameters) appearing? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
akorx Posted February 3, 2012 Author Share Posted February 3, 2012 (edited) akorx,I know RunAs exists. If you type " RunAs(" into your script, do you get the CallTip (the list of parameters) appearing? M23Yes the list appears... i use RunAs (not "rusas", i have made an error when i have posted my script but on my real scrip it's written "runas"). Edited February 3, 2012 by akorx AkorxMail akorx@yahoo.fr Link to comment Share on other sites More sharing options...
akorx Posted February 3, 2012 Author Share Posted February 3, 2012 (edited) http://www.autoitscript.com/autoit3/docs/functions/RunAs.htmScite isn't nearly as helpful as the help file. Press F1 when you are using scite. The help file should be your best friend. It will not allow you to run a function, but it will allow you to run a script. If you want to run a function with admin status, I reccommend you use paramaters. For example, you use the parameter -a to have the program run the function. If you don't understand how to do this, I will attach some code in a minute.I'm using F1... but what do you mean when you say "use the parameter -a to have the program run the function" ? you are using a program that calls another ? i would like to have all the things in just ONE script .... can you give me an example ? Edited February 3, 2012 by akorx AkorxMail akorx@yahoo.fr Link to comment Share on other sites More sharing options...
Mikeman27294 Posted February 3, 2012 Share Posted February 3, 2012 (edited) I'm using F1... but what do you mean when you say "use the parameter -a to have the program run the function" ? you are using a program that calls another ? i would like to have all the things in just ONE script .... can you give me an example ? I'm glad you asked. Here it is. As you can see, it is just 1 script. For $Repeat = 1 To $CmdLine[0];The $cmdline array is automatically set by autoit. It contains any parameters given to the program when it is run. ;Hold Shift and press F8 in scite to set parameters. Enter "a" into the first box, without quotes. MsgBox(0,"",$CmdLine[$Repeat]) ;For debug reasons - shows you what the current parameter is. If $CmdLine[$Repeat] = "a" Then ;Checks to see that the current parameter is "a" _AdminFunction() EndIf Next If @Compiled = 1 Then RunAs(InputBox("Username", "Insert the username of the administrator", "Administrator"), "", InputBox("Password", "Insert the password of the admin account.", ""), 0, FileGetShortName(@ScriptFullPath) & " a");Runs the compiled script with the a parameter Else RunAs(InputBox("Username", "Insert the username of the administrator", "Administrator"), "", InputBox("Password", "Insert the password of the admin account.", ""), 0, FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)& " a");Runs the uncompiled script with the a parameter EndIf Func _AdminFunction() If IsAdmin() Then;Ensures that the current user is admin as a normal user could run the program with the parameter set (if they have access to the code or try the parameter by pure chance to see what it does) MsgBox(0,"","Running Function as Admin") ;You can place your required script here. Else MsgBox(0,"","Running Function as Normal User. Function will not attempt") ;Function is not run be an administrator and so it will exit. EndIf Exit EndFunc I'm actually quite proud of it, myself. The comments explain what happens, but I will explain it too. The first thing the program does, is checks all parameters passed to it. If one of them is the parameter "a" then it runs the "_AdminFunction". If not, then it exits the for loop, and asks you for credentials. If the credentials are correct, it runs the program with the specified parameter. If not, then the run function doesn't run the program. In the "_AdminFunction" it ensures the user is admin, incase by pure chance, the program is run with this parameter by a normal user. This can also be done if the person inserts the credentials for a non-administrator account. If the user is an administrator, it displays the message to say so. If not, again, it displays a message to say they are not. Please note that I have run this from the guest account, trying both guest credentials, and admin credentials. I tried both compiled and non-compiled, so it should work for you exactly as it worked for me. Edited February 3, 2012 by Mikeman27294 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2012 Moderators Share Posted February 3, 2012 akorx,I have just reread your initial post:how can i do to run a function (not a external program but a autoit function like regwrite) with admin rights ?To the best of my knowledge you cannot run a single function in an AutoIt script with admin rights - you must elevate the whole script with #requireadmin. If it is a relatively simple thing that you want to want to run elevated, then you can compile a separate script containing the necessary code with #requireadmin and use RunAs to run it from your user-level script. As to why RunAs does not appear in the same colour as the other functions - check that "RunAs" exists in this file:"C:Program FilesAutoIt3SciTEPropertiesau3.keywords.properties"as this is the file SciTE uses to colour the name in the correct fashion. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
akorx Posted February 5, 2012 Author Share Posted February 5, 2012 I'm glad you asked. Here it is. As you can see, it is just 1 script. For $Repeat = 1 To $CmdLine[0];The $cmdline array is automatically set by autoit. It contains any parameters given to the program when it is run. ;Hold Shift and press F8 in scite to set parameters. Enter "a" into the first box, without quotes. MsgBox(0,"",$CmdLine[$Repeat]) ;For debug reasons - shows you what the current parameter is. If $CmdLine[$Repeat] = "a" Then ;Checks to see that the current parameter is "a" _AdminFunction() EndIf Next If @Compiled = 1 Then RunAs(InputBox("Username", "Insert the username of the administrator", "Administrator"), "", InputBox("Password", "Insert the password of the admin account.", ""), 0, FileGetShortName(@ScriptFullPath) & " a");Runs the compiled script with the a parameter Else RunAs(InputBox("Username", "Insert the username of the administrator", "Administrator"), "", InputBox("Password", "Insert the password of the admin account.", ""), 0, FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)& " a");Runs the uncompiled script with the a parameter EndIf Func _AdminFunction() If IsAdmin() Then;Ensures that the current user is admin as a normal user could run the program with the parameter set (if they have access to the code or try the parameter by pure chance to see what it does) MsgBox(0,"","Running Function as Admin") ;You can place your required script here. Else MsgBox(0,"","Running Function as Normal User. Function will not attempt") ;Function is not run be an administrator and so it will exit. EndIf Exit EndFunc I'm actually quite proud of it, myself. The comments explain what happens, but I will explain it too. The first thing the program does, is checks all parameters passed to it. If one of them is the parameter "a" then it runs the "_AdminFunction". If not, then it exits the for loop, and asks you for credentials. If the credentials are correct, it runs the program with the specified parameter. If not, then the run function doesn't run the program. In the "_AdminFunction" it ensures the user is admin, incase by pure chance, the program is run with this parameter by a normal user. This can also be done if the person inserts the credentials for a non-administrator account. If the user is an administrator, it displays the message to say so. If not, again, it displays a message to say they are not. Please note that I have run this from the guest account, trying both guest credentials, and admin credentials. I tried both compiled and non-compiled, so it should work for you exactly as it worked for me. Thx for your code Mikeman27294, it 's not what i really want in this case but i keep it for improve another script that i've got, it's a good script that will help me ! AkorxMail akorx@yahoo.fr Link to comment Share on other sites More sharing options...
akorx Posted February 5, 2012 Author Share Posted February 5, 2012 akorx,I have just reread your initial post:To the best of my knowledge you cannot run a single function in an AutoIt script with admin rights - you must elevate the whole script with #requireadmin. If it is a relatively simple thing that you want to want to run elevated, then you can compile a separate script containing the necessary code with #requireadmin and use RunAs to run it from your user-level script. As to why RunAs does not appear in the same colour as the other functions - check that "RunAs" exists in this file:"C:Program FilesAutoIt3SciTEPropertiesau3.keywords.properties"as this is the file SciTE uses to colour the name in the correct fashion. M23I'm not at work but i will verify on monday...Do you know where i can suggest to developpers of Autoit to try to add this kind of fonction? i think that a lot of people would like to have it.=> please correct my last expression because i think it's not really english ! what is the good expression ? AkorxMail akorx@yahoo.fr Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 5, 2012 Moderators Share Posted February 5, 2012 akorx,Do you know where i can suggest to developpers of Autoit to try to add this kind of fonction? i think that a lot of people would like to have it.You can ask for additional features to be added to AutoIt via the "Bug Reports and Feature Requests" link on the forum home page. But I would counsel you NOT to ask for this as it will almost certainly be refused. Why? Because you can very easily run your whole script at the elevated level (Mikeman27294's script just reruns itself elevated ) or you can do what I suggested and run a separate script elevated to run specific functions. If you want an example of how to do that take a look at how the RunReqAdmin function in Jos' SciTEConfig does its magic (lines 1230 to 1246 in my version). M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Blue_Drache Posted February 5, 2012 Share Posted February 5, 2012 Melba: Actually, this kind of request happens about once every 3 months or so. I don't really like the idea, much less think it's possible, to tell the truth, since a program really only asks if you should grant admin privileges once. And windows grants it once... even if there are multiple administration level calls. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 5, 2012 Moderators Share Posted February 5, 2012 Blue_Drache, Which is what I said a few posts above. The post immediately above was explaining why there was no chance of a feature request ever being approved given that it is easy to do with existing code. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts