Guest Posted October 25, 2013 Posted October 25, 2013 hello, Sometimes my script need to #RequireAdmin but not always. so i want to do that the script will require admin when i call to some function or if some condition is exist. Unfortunately it does not work. in this test: MsgBox(0,"","test") Func test() #RequireAdmin EndFunc I expected that the script will not require admin because I didn't call to test(). but what actually happened is that the script requireed admin anyway.. Do you know a method to do what I'm trying to do?
Moderators Melba23 Posted October 25, 2013 Moderators Posted October 25, 2013 gil900,Directive like #requireadmin cannot be conditional - AutoIt looks for them at runtime and actions any that exist before running the script. The only way I know to work around this is to use a wrapper script that determines whether #requireadmin is needed and then calls the relevant version of the working script (with and one without the directive). 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
Guest Posted October 25, 2013 Posted October 25, 2013 gil900, Directive like #requireadmin cannot be conditional - AutoIt looks for them at runtime and actions any that exist before running the script. The only way I know to work around this is to use a wrapper script that determines whether #requireadmin is needed and then calls the relevant version of the working script (with and one without the directive). M23 If it requires another exe file, so it's not an option for me ...Anyone know another way?
Solution KaFu Posted October 25, 2013 Solution Posted October 25, 2013 Check my example here: '?do=embed' frameborder='0' data-embedContent>> OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Moderators Melba23 Posted October 25, 2013 Moderators Posted October 25, 2013 gil900, If it requires another exe file, so it's not an option for meYou can do it with .au3 or .a3x files - just FileInstall the one you need and get the original .exe to run it. 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
Guest Posted October 25, 2013 Posted October 25, 2013 Check my example here: '?do=embed' frameborder='0' data-embedContent>> Thank you.this solution is almost perfect. You said in this thread that you heard that someone's been working on a solution to do this in runtime. Does anyone already done such a solution? if not then i will use your example thank you!
Guest Posted October 25, 2013 Posted October 25, 2013 Another solution If Not _GetDebugPrivilegeRtl() Then #RequireAdmin EndIf Func _GetDebugPrivilegeRtl() Local $aRet = DllCall('Ntdll.dll', "long", "RtlAdjustPrivilege", "ulong", 20, "bool", True, "bool", False, "bool*", 0) Return $aRet[0] = 0 EndFunc ;==>_GetDebugPrivilegeRtl Have you checked what you gave?It does not work and I think it also should not work ... But thanks for trying to help
Moderators Melba23 Posted October 25, 2013 Moderators Posted October 25, 2013 Mrbenkali,As I explained above, that code will NOT work as AutoIt looks for and actions all directives BEFORE running the script. So you CANNOT have conditional directives and need a workaround - either restarting the script (as Kafu has very cleverly done) or running different versions of a child script. M23 Celtic88 1 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
Guest Posted October 25, 2013 Posted October 25, 2013 If no one will bring a better solution in the next 5 hours, KaFu win the best answer vote (Mark Solved) Thanks you for your help!
Celtic88 Posted October 25, 2013 Posted October 25, 2013 Melba23 Ah sorry ,I have not read your message thank you.
DXRW4E Posted October 25, 2013 Posted October 25, 2013 MsgBox(0,"","test") If Not IsAdmin() Then _GetAdminRight() MsgBox(0,"","test2") Func _GetAdminRight($sCmdLineRaw = "") If Not IsAdmin() Then If Not $sCmdLineRaw Then $sCmdLineRaw = $CmdLineRaw ShellExecute(@AutoItExe, $sCmdLineRaw, "", "runas") ProcessClose(@AutoItPID) Exit EndIf EndFunc Ciao.
Guest Posted October 25, 2013 Posted October 25, 2013 (edited) MsgBox(0,"","test") If Not IsAdmin() Then _GetAdminRight() MsgBox(0,"","test2") Func _GetAdminRight($sCmdLineRaw = "") If Not IsAdmin() Then If Not $sCmdLineRaw Then $sCmdLineRaw = $CmdLineRaw ShellExecute(@AutoItExe, $sCmdLineRaw, "", "runas") ProcessClose(@AutoItPID) Exit EndIf EndFunc Ciao. What you have done is a better packaging of the same solution.I'm not looking better packaging ..I was looking for a better solution.But no matter .. I have been implementing the solution of KaFu anyway...It seems to be good enough for me Edited October 25, 2013 by Guest
DXRW4E Posted October 25, 2013 Posted October 25, 2013 (edited) What you have done is a better packaging of the same solution.I'm not looking better packaging . I was looking for a better solution. I gave you just a alternative to what you asked (not logical and bad example) in the first post of the topic, nothing else OKKKKKK Ciao. Edited October 25, 2013 by DXRW4E
Guest Posted October 25, 2013 Posted October 25, 2013 I gave you just a alternative to what you asked (not logical and bad example) in the first post of the topic, nothing else OKKKKKK Ciao. It's okay ..Thank you for the help!
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