Jump to content

UAC and Exit Codes


Recommended Posts

Hi,

I've got an AutoIt script that acts as a pre-loader to run other AutoIt scripts to determine if certain prerequisites are installed. All these scripts are compiled to EXE with the #RequireAdmin directive. So, for example, if an application requires .NET Framework 2.0, the main AutoIt script runs a second script (as an elevated user) to 1) verify that .NET Framework 2.0 is/is not installed and return a flag via exit code then 2) install .NET Framework 2.0 if the return code was "not installed". This has worked quite well up until a few days ago when some of the users switched to Windows 7 64-bit (though because it appears to be UAC related, it may affect 32-bit as well). The ones with UAC turned completely off had no issue (other than a logic bug). The ones with UAC left on are having the second script run every time, regardless of whether the .NET Framework 2.0 is present or not.

From reading the forums and from how the other machines act, I can simply turn of UAC and that will fix the problem, but I'd like to see if there's a way to get this working with UAC turned on (since that would seem to be the more secure route). Here's what I'm doing with some example code using the .NET Framework 2.0 script:

The NETF2 script accepts a command line parameter "-check". This parameter tells the subscript to do whatever check it normally does and return either "Exit 1" or "Exit 0" depending on if .NETF2 was found. UAC causes a problem (from what I've found on the forums and from experimenting) in that when I launch the .NETF2 checker from my main program, the UAC prompt process and the actual run of .NETF2 have 2 different process IDs (and are thus 2 different runs). So this makes my RunAsWait ineffective because it exits when the UAC prompt is acknowledged.

Main App

$exit = RunAsWait('Super','Domain','Password',0,'C:\NETF2.exe','C:\')
MsgBOx(0, 'Test', $exit)

NETF2 App

#RequireAdmin
...
If FileExists($checkFile) Then 
    Exit 1 
Else 
    Exit 0
EndIf

With this, the message box appears before the .NETF2 app even starts running because the UAC process is closed. So I thought I'd try to re-catch the process and get its exit code. For some reason, this always results in the 0xCCCCCCCC exit code.

Main App

$exit = RunAsWait('Super','Domain','Password',0,'C:\NETF2.exe','C:\')
$2ndPID = ProcessWait('NETF2.EXE')
$rtn = ProcessWaitClose($2ndPID)
$exit = @extended

So this would appear to work as my process ID for the 2nd instance would match what the app thought its PID was (via MsgBox(0, "", @AutoItPID) added to NETF2 script). So I'm getting the right process, I'm waiting until its done running, but the exit code is useless as its not the .NETF2 exit code. I can't find a good explanation anywhere as to what the 0xCCCCCCCC exit code should indicate other than an invalid PID, which shouldn't be the case here.

So hopefully that's not too confusing, but I'm wondering where to go from here. Discussing with another developer, I think I have a work around that relies on creating and killing registry key entries for the subprograms, but I wanted to see if there was a way to just get the exit code as before.

Any help is greatly appreciated.

Chris

Link to comment
Share on other sites

Thanks for the suggestions.

BTW, I'm compiling with 3.3.6.1 (guess I should have mentioned that before).

I saw the #AutoIt3Wrapper_res_requestedExecutionLevel noted elsewhere, but when I use it, it makes no difference. The exe doesn't run elevated and doesn't prompt the UAC. Is this just a version thing? The wrapper seems to recognize the flag, but there's no discernable change while running. AutoItWrapper says it's version 1.10.1.8.

I tried just elevating the main program and that seemed to work OK. The only issue there is that there's another application that references the subprograms that's not currently elevating itself. I'll have to look into making that program elevate itself, but it would be nice if I could get away with just elevating the subprograms. Oh well.

Thanks again!

Chris

Link to comment
Share on other sites

@DirtyMonkeyXXX

Install SciTE4AutoIt3 from HERE. It brings loads of tools and goodies. You could even say that AutoIt isn't complete without it.

@Whoever is interested.

#RequireAdmin checks if the script is admin, and if not restarts the script. That means exit-codes, stdio and what-not will not work.

requestedExecutionLevel will cause the UAC dialog at start, so there's no weird breaking. I don't think so anyway, I don't know everything (or do I? ;)).

So #RequireAdmin is pretty much pointless nowadays. If you want something like this to work:

#RequireAdmin
ConsoleWrite("Hello. World!" & @CRLF)

Just right-click SciTE and [Run as administrator].

Link to comment
Share on other sites

Grabbed the lastest AutoIt/SciTE/Wrapper, I was quite out of date (new version is 2.0.1.24). So now the requestedExecutionLevel directive is working. But I'm having a new problem. The subprogram doesn't appear to run if both applications include the requestedExecutionLevel=requireAdministrator directive. If I compile the subprogram (which at this point just pops up a message box to say its been executed) without the directive, I get the message box (I also tested just launching notepad, which also worked), but if I compile the subprogram with the requireAdministrator flag, I can see in Process Explorer that it opens and closes immediately with no message box pop-up whatsoever. Any ideas with why the 2nd app wont run?

Thanks,

Chris

Link to comment
Share on other sites

Yes, I removed it. If I run the main program, I only get the UAC notification for that program (so no more subprogram opening and requesting authority and closing). If I run the subprogram independantly, I get a UAC request for that. So it appears the security is all worked out. I thought maybe it was because the app was not running at all, but like I said, using Process Explorer, I can see the sub program startup and close immediately, so I know its running, it just appears its not actually going into the code at all.

Link to comment
Share on other sites

  • 1 year later...

Hi

1: Open your au3 source script

2: Press CTRL+F7

3: Select "Resource Update"

4: Select "Execution level"

5: Select "requireAdministrator"

6: Select "Compile Script"

You don't need to remember this, or script anything like e.g. #RequireAdmin,

because now this "requireAdministrator manifest" is part of your source script:

#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator

From now on, no one can run your compiled exe file,

without being prompted with an UAC elevation to run as administrator

Sincerely

Jorgen Malmgren

IT-Programmer

Denmark - UTC+1

www.tryware.dk

;o) Your brain is like a parachute. It works best when it's

Sincerely

J. Malmgren

IT-Programmer

http://www.tryware.dk

 

Link to comment
Share on other sites

@nergmlam

I'm not sure if you're aware of this or not, but most of the topics you're responding to are about 2 years old. I don't think the posters to the threads have much use of the information. Just an FYI.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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