Sign in to follow this  
Followers 0
gil900

Require Admin only when it is necessary

14 posts in this topic

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?

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

gil900,

 

If it requires another exe file, so it's not an option for me

You 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

 

Another solution   :bye: 

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

Share this post


Link to post
Share on other sites

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

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
Melba23

 

Ah sorry ,I have not read your message thank you.  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 by gil900

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
Share on other sites

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!

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  
Followers 0