Jump to content

Run a program with requireAdmin from an AutoIt program


dolphins
 Share

Recommended Posts

Hi,

I have an AutoIt program that is using "Run" to start another AutoIt program that has #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator set (the caller doesn't have Admin rights). This doesn't work (at leat I wasn't able to make it work). So I called a bat file and that bat file started the 2nd AutoIt program. This works. But one can see the black Dos Box on the Screen. If I this @SW_HIDE the black dos box doesn't appear but also the UAC prompt doesn't come into front, it is in the Background and the user Need to click at it to see that Dialog. That is not comfortable for the user.

Any way to not Show that black dos box and have the UAC prompt on top of the Screen?
Or is it possible to Run an AutoIt program with #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator from an AutoIt program that doesn't have #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator.
Any other suggestions?

Regards
dolphins

Link to comment
Share on other sites

I'd run with full rights as a scheduled task.  You can invoke that without admin, but because the credentials are linked with the task, it runs without UAC.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

The caller script does not have admin rights. Well, not sure about ShellExecute, since I don't want to give other credentials when not necessary. Also I don't know the password of the current user. So if I understand ShellExecute right, it doesn't fit my needs.

The suggestion to use AutoIt to bring the UAC window to the top is not possible when I start the 2nd AutoIt program from a bat-file, isn't it? Since in that moment there is no AutoIt program running.

Link to comment
Share on other sites

Ok, here some code. I made the sample code as short as possible.

 

Main program:
 

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <array.au3>
#include <string.au3>
#include <Date.au3>

_Main()
Func _Main()

    Func1()

EndFunc


Func Func1()

    $Form1        = GUICreate("Main", 800, 550)
    $btnUpdate = GUICtrlCreateButton("Update", 35, 220, 145, 33)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetOnEvent($btnUpdate, "Update_Button")

    GUISetState(@SW_SHOW, $Form1)
    While 1
            $msg = GUIGetMsg()
            Select
               Case $msg = $btnUpdate
                    GUISetState(@SW_HIDE, $Form1)
                    Sub_Update()
               Case $msg = $GUI_EVENT_CLOSE
                    Exit
            EndSelect
    WEnd

    GUISetState(@SW_SHOW, $Form1)

EndFunc


Func Sub_Update()

    $zwi = @ScriptDir & "\upd.bat "
    $pid = Run($zwi, @ScriptDir)

    If $pid = 0 And @error <> 0 Then
       MsgBox(16,"Error", "Update.exe error;" & @error)
    Else
       Exit
    EndIf

EndFunc

 

Sub program:
 

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <array.au3>
#include <string.au3>

_Main()

Func _Main()

    $FormSub    = GUICreate("Sub", 680, 100, 200, 50)
    GUISetState(@SW_SHOW, $FormSub)
    GUICtrlCreateLabel("some info ...", 35, 25, 650, 28)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    Sub_Start()

    GUIDelete($FormSub)

EndFunc


Func Sub_Start()

    MsgBox(0, "Sub", "Update is going on ...")

    $zwi = @ScriptDir & "\Main.exe "
    $retCode = Run($zwi, @ScriptDir)

    If $retCode = "0" And @error <> 0 Then
       MsgBox(16, "Error Sub", "Some error text;" & @error)
    EndIf

    Exit

EndFunc

 

Upd.bat:
 

@echo off
Start sub.exe

 

The main program is compiled with 3.3.8.1, the Sub program is compiled with 3.3.14.0

The main program has the User GUI. In this sample I made a button to start the Update (in the real main, it checks for date and Version versus a file in the Internet). This button removes the User GUI and starts Upd.bat. Upd.bat start Sub.exe. Sub.exe Shows a running message and after the update is done calls main.exe again. When the Upd.bat starts Sub.exe the UAC Dialog appears, but in Background and not on top of all Windows.

- How can I bring the UAC Dialog to top without showing the black dos Box?

- Or how can I start the Sub.exe and showing the UAC Dialog asking for admin rights without giving new credentials, when the current user has admin rights (when the user has no admin rights it should prompt for user Name and Password with admin rights)

Edited by dolphins
Link to comment
Share on other sites

  • 5 years later...
On 2/20/2016 at 1:11 PM, jguinch said:

If I understand your problem, you should use ShellExecute instead of Run

 

Thanks, that also solved my problem! Now I can start a non-elevated script and in there an elevated script that contains an #RequireAdmin !

“It is only when a mosquito lands on your testicles that you realize there is always a way to solve problems without using violence.”
― Confucius

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