Jump to content

Require Admin only when it is necessary


Guest
 Share

Go to solution Solved by KaFu,

Recommended Posts

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?

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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?

Link to comment
Share on other sites

  • Solution
  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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.

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

Link to comment
Share on other sites

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 Guest
Link to comment
Share on other sites

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

Link to comment
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!

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