Jump to content

Advanced RequireAdmin


elawady
 Share

Recommended Posts

when i write script to run it in startup have this #RequireAdmin message every startup and it make me crazy :lol:

i need something to run script like that

statements

$reg = IniRead ( @AppDataDir&"\count.ini", "info", "reg","off" )
If $reg = "off" Then
        #RequireAdmin
    FileCopy(@ScriptFullPath,@ProgramFilesDir&"\counter\"&@ScriptName)
    RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","counter","REG_SZ",@ProgramFilesDir&"\counter\"&@ScriptName&" \count")
    IniWrite ( @AppDataDir&"\count.ini", "info", "reg" ,"on")
EndIf

statements ........

func _function()
#RequireAdmin

statements

endfunc

when change setting only the #RequireAdmin work :mellow::(

Link to comment
Share on other sites

Does your script need Admin-Rights only once?

Then take all Admin operations and put them in a separate script. This will run with #requireAdmin (FileInstall, ShellExecuteWait, FileDelete, check an Ini value if it succeeded)

*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

Link to comment
Share on other sites

Put everything in one script, use commandline-parameters to choose the action. Run the admin-commands with ShellExecute and Verb runas:

Switch $CMDLINE[0]
    Case 1
        If $CMDLINE[1] = "-installadmin"
            ; do admin tasks here
            Exit
        ElseIf $CMDLINE[1] = "-uninstalladmin"
            ; do Uninstall here
            Exit
        EndIf
EndSwitch
    
; normal script
If $DO_ADMIN_TASKS Then 
    ShellExecuteWait(@AutoItExe, $CMDLINERAW & " -installadmin", @WorkingDir, "runas") ; $CMDLINERAW is needed that it works with uncompiled scripts, too.
    ...
EndIf

*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

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