Jump to content

Run cannot run my EXE, ShellExecute can (UAC involved)


Go to solution Solved by Jos,

Recommended Posts

Posted (edited)

Hi,

I know Run and ShellExecute are not the same but I really wonder if the following is a bug or not.

I have an AutoIT exe that I run by double-clicking the file in Windows (it runs in the current user profile) . It then runs another AutoIT exe which has the #RequireAdmin option.
When I use Run() it doesn't run, PID is 0 and @error flag is 1. If I use ShellExecute() it runs fine.

Should I create a bug report?

Edited by ElwoodB

Philippe
Amiga user

  • Developers
Posted
2 hours ago, ElwoodB said:

Should I create a bug report?

Not really yet. ;) 

First provide some sort of replication scripts so we can see what you are exactly doing and we can see it for ourselves.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Hi Jos,

Here are two scripts.

Runme-first.au3

#NoTrayIcon
#include <MsgBoxConstants.au3>

Opt('MustDeclareVars', 1)

Local $pid

If FileExists(@ScriptDir & "\runas-admin.exe") Then
    $pid = Run(@ScriptDir & "\runas-admin.exe")
    If $pid = 0 Then
        MsgBox($MB_OK,"Cannot Run() runas-admin.exe",@error)
    EndIf
    $pid = ShellExecute(@ScriptDir & "\runas-admin.exe")
    If $pid = 0 Then
        MsgBox($MB_OK,"Cannot ShellExecute() runas-admin.exe",@error)
    EndIf
EndIf

Exit 0

Runas-admin.exe :

#NoTrayIcon
#RequireAdmin
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)
Opt("GUICoordMode", 1) ;1=absolute, 0=relative, 2=cell

MsgBox($MB_OK,"username is",@UserName)

Exit 0


About the environnment

I am on a Windows Server 2022 which is connected to an Active directory. I am logged as a user with admin rights (so I can right click a binary and select "Run as administrator". I have this UAC warning and when I click Yes, the program is executed.
image.png.19951cc322887fbf13ccde0d886feb6a.png


Test :

I run "runme-first" by double-clicking the .exe.
It cannot Run(runas-admin.exe) and it displays @error = 1
And then it can ShellExecute() the same binary and displays the current username.

Philippe
Amiga user

Posted (edited)

Thanks for pointing that out.

By reading Jon answer from 10 years ago, came to my mind the same questions of the two comments below Jon's.
When I read this Jon's comment, I'm sure a small explanation have to go to the Run() help file.

Quote

The default function to use would be ShellExecute really.

I propose :

Quote

Note: if you intend to run a program that requires elevation through UAC, you need to use ShellExecute() instead as it handles elevation if needed. Run() does not.

 

Edited by ElwoodB

Philippe
Amiga user

  • ElwoodB changed the title to Run cannot run my EXE, ShellExecute can (UAC involved)

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