Sign in to follow this  
Followers 0
pcjames

How to use #RequireAdmin

16 posts in this topic

Hi All, I have a quick newbie question... If I have a script for installing programs should I use #RequireAdmin only once at the beginning of the script or should I use it before each program my script installs?

Thanks in advance for you help, James

Share this post


Link to post
Share on other sites



Only once.

Share this post


Link to post
Share on other sites

#RequireAdmin = UAC = The Manifest = The manifest is an XML resource file, An example manifest file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

Level

1 asInvoker
2 highestAvailable
3 requireAdministrator

Share this post


Link to post
Share on other sites

@ Inverted, Thanks a bunch, wasn't really sure, the documentation doesn't say either way.

#RequireAdmin = UAC = The Manifest = The manifest is an XML resource file, An example manifest file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

Level
1 asInvoker
2 highestAvailable
3 requireAdministrator
@ DCCD, I'm new at autoit and I know that your trying to explain about Vista's UAC but I'm not sure what to do with this information, Could you explain in further detail?

Thanks

Share this post


Link to post
Share on other sites

Vista looks for a xml manifest file. It's either in the same folder as the executable or it can be included in the executable itself in the resources section (that's what AutoIt does)

So, #RequireAdmin does that.

If I'm wrong someone correct me please.

Share this post


Link to post
Share on other sites

Vista looks for a xml manifest file. It's either in the same folder as the executable or it can be included in the executable itself in the resources section (that's what AutoIt does)

So, #RequireAdmin does that.

I'm guessing here but If I make a script for Vista in the folder where I have my script and executable I need to include say ????.xml file? If this is correct, does it matter what the .xml file name is?

Share this post


Link to post
Share on other sites

Thanks DCCD, I understand now, when #RequireAdmin is used, Vista will create the Manifest XML and embedded into my application. Sorry for being so ignorant about your first post

#RequireAdmin = UAC = The Manifest = The manifest is an XML resource file, An example manifest file

I should of got it with the "=" but I just wanted to make sure!

Thanks to both of you for the information! James

Share this post


Link to post
Share on other sites

Vista looks for a xml manifest file. It's either in the same folder as the executable or it can be included in the executable itself in the resources section (that's what AutoIt does)

So, #RequireAdmin does that.

If I'm wrong someone correct me please.

AutoIt is doing that differently.

But you described how AutoIt3Wrapper is doing it. That's nice.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

How is AutoIt doing it ? I was wondering what difference is between #RequireAdmin and that option in AutoItWrapper ...

Share this post


Link to post
Share on other sites

How is AutoIt doing it ? I was wondering what difference is between #RequireAdmin and that option in AutoItWrapper ...

I don't know.

But if someone would ask me to speculate or maybe to offer a solution if #RequireAdmin is not existing I would say this:

If Not IsAdmin() Then
    ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '"', "", "runas")
Else
    MsgBox(0, @ScriptFullPath, "Admin Rights: " & (IsAdmin() = 1) & @CRLF)
EndIf

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

I don't know.

But if someone would ask me to speculate or maybe to offer a solution if #RequireAdmin is not existing I would say this:

If Not IsAdmin() Then
    ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '"', "", "runas")
Else
    MsgBox(0, @ScriptFullPath, "Admin Rights: " & (IsAdmin() = 1) & @CRLF)
EndIf
i like it,

Add a UAC shield to a button, I added a key "Test" to HKEY_LOCAL_MACHINE\SOFTWARE\

=======

#include <GUIConstants.au3>

GUICreate("Under Vista") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("Run As Admin",  10, 30, 100)
$Button_2 = GUICtrlCreateButton ( "RegWrite",  0, -1)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '"', "", "runas")
            ;Exit
        Case $msg = $Button_2
            $eee= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")
            if $eee = 1 Then
                MsgBox(0, 'Testing', 'Success')
            Else
                MsgBox(0, 'Testing', 'Failure')
            EndIf
    EndSelect
Wend

Share this post


Link to post
Share on other sites

i like it,

Add a UAC shield to a button, I added a key "Test" to HKEY_LOCAL_MACHINE\SOFTWARE\

=======

#include <GUIConstants.au3>

GUICreate("Under Vista") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("Run As Admin",  10, 30, 100)
$Button_2 = GUICtrlCreateButton ( "RegWrite",  0, -1)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '"', "", "runas")
            ;Exit
        Case $msg = $Button_2
            $eee= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")
            if $eee = 1 Then
                MsgBox(0, 'Testing', 'Success')
            Else
                MsgBox(0, 'Testing', 'Failure')
            EndIf
    EndSelect
Wend
You can do that even cooler. I added button 3:

#include <GUIConstants.au3>

GUICreate("Under Vista"); will create a dialog box that when displayed is centered

Opt("GUICoordMode", 2)
$Button_1 = GUICtrlCreateButton("Run As Admin", 10, 30, 100)
$Button_2 = GUICtrlCreateButton("RegWrite", 0, -1)
$Button_3 = GUICtrlCreateButton("RegWriteFromHere", 0, -1)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '"', "", "runas")
        ;Exit
        Case $msg = $Button_2
            $eee = RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")
            If $eee = 1 Then
                MsgBox(0, 'Testing', 'Success')
            Else
                MsgBox(0, 'Testing', 'Failure')
            EndIf
        Case $msg = $Button_3
            ShellExecuteWait(@AutoItExe, '/AutoIt3ExecuteLine  "RegWrite(''HKEY_LOCAL_MACHINE\SOFTWARE\Test'', ''TestKey2'', ''REG_SZ'', ''Hello this is a test'')"', "", "runas")
    EndSelect
WEnd

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

The UAC shield can be controlled with those SendMessage-Calls: (MSDN)

#include<ButtonConstants.au3>
GUICtrlSendMsg($idButton, $BCM_SETSHIELD, 0, True) ; Activate UAC shield
GUICtrlSendMsg($idButton, $BCM_SETSHIELD, 0, False) ; Deactivate UAC shield
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#RequireAdmin does not add any kind of tag to the executable. It just has the interpreter check to see if it has admin powers and if not, runs the script again. It's not as fancy as you make it out to be.

Share this post


Link to post
Share on other sites

#RequireAdmin does not add any kind of tag to the executable. It just has the interpreter check to see if it has admin powers and if not, runs the script again. It's not as fancy as you make it out to be.

Ok, then like trancexxx already said, I was describing how #AutoIt3Wrapper works.

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