Jump to content

Recommended Posts

Posted

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

Posted

The UAC itself is not the problem. With the bat-file I just want that the UAC comes on top of all windows, but it doesn't when I use @SW_HIDE.

Posted

You can use autoit functions to bring the UAC window on TOP.

Otherwise I havent tested , but i think if caller script is with admin rights - then the subscript will have admin rights too.

Posted

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.

Posted

Oh, just got an idea. Right now I quit the caller program after calling the bat-file. Maybe after calling the bat file, I can look for the UAC window, bring it to top, and then exit the caller program. Hmmmm.

Posted (edited)

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
Posted

Winactivate() should be the easiest way to activate the UAC. 
You should need no BAT file - just use shellexecute the second autoit exe file and there will be no cmd black box.

Posted

Thanks, I got it working now with ShellExecute. Somehow I thought I had to give new credentials when using ShellExecute like RunAsWait for example, but that is nonsense. It works fine now. Thanks a lot !

Posted

Correct! I had a wrong information about ShellExecute in my head, so I didn't take a look in the help immediately. After I took that hurdle, it was easy going :)

  • 5 years later...
Posted
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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...