ElwoodB Posted June 20, 2023 Posted June 20, 2023 (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 July 4, 2023 by ElwoodB PhilippeAmiga user
Developers Jos Posted June 20, 2023 Developers Posted June 20, 2023 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.
ElwoodB Posted June 26, 2023 Author Posted June 26, 2023 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. 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. PhilippeAmiga user
Developers Solution Jos Posted June 26, 2023 Developers Solution Posted June 26, 2023 Ok.. i believe this is by design: 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.
ElwoodB Posted June 27, 2023 Author Posted June 27, 2023 (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 June 27, 2023 by ElwoodB PhilippeAmiga user
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now