VeeDub_1 Posted 20 hours ago Posted 20 hours ago Hello, I'm trying to use runas on W11 x64 to run a program under admin credentials. The example below is from W10 X64 which has the same behaviour. This program works with: C:\Windows\System32\notepad.exe But not when the executable is in: Program Files (x86) expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <AutoItConstants.au3> RunAsAdmin() Func RunAsAdmin() ; Change the username and password to the appropriate values for your system. Local $sUserName = "Admin" Local $sDomain = "domain" Local $sPassword = "password" Local $sProgram = """C:\Program Files (x86)\Advanced IP Scanner\advanced_ip_scanner.exe""" Local $Status $Status = FileExists($sProgram) ConsoleWrite("Program:" & $sProgram & @CRLF) ConsoleWrite("Status: " & $Status & @CRLF) ; Run Notepad with the window maximized. Notepad is run under the user previously specified. Local $iPID = RunAs($sUserName, $sDomain, $sPassword, $RUN_LOGON_PROFILE, $sProgram, "", @SW_SHOWMAXIMIZED) ConsoleWrite("PID: " & $iPID & @CRLF) ; Wait 10 seconds for the Notepad window to appear. ; WinWait("[CLASS:Notepad]", "", 10) ; Wait for 2 seconds. ; Sleep(10000) ; Close the Notepad process using the PID returned by RunAs. ; ProcessClose($iPID) EndFunc ;==> RunAsAdmin >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\Temp\BE\Runas_Admin\Launch_BTS.au3" /UserParams +>13:42:43 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_10/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\ZEN\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\ZEN\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.16.1) from:C:\Program Files (x86)\AutoIt3 input:D:\Temp\BE\Runas_Admin\Launch_BTS.au3 +>13:42:43 AU3Check ended.rc:0 >Running:(3.3.16.1):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "D:\Temp\BE\Runas_Admin\Launch_BTS.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. Program:"C:\Program Files (x86)\Advanced IP Scanner\advanced_ip_scanner.exe" Status: 0 PID: 0 +>13:42:44 AutoIt3.exe ended.rc:0 +>13:42:44 AutoIt3Wrapper Finished. >Exit code: 0 Time: 2.272 In the example, the path exists, but AutoIt can't see it. I have found some cryptic info in the help under 'Running under Windows 64 bit Edition', which doesn't help. After an explanation or some troubleshooting suggestions. Thanks VW
argumentum Posted 20 hours ago Posted 20 hours ago Why """C:\Program Files (x86)\Advanced IP Scanner\advanced_ip_scanner.exe""" ? Why not "C:\Program Files (x86)\Advanced IP Scanner\advanced_ip_scanner.exe" ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted 19 hours ago Posted 19 hours ago ..tested in 25H2 and I did not get it do run as admin. In any case, when I need to run as admin, I add it to task scheduler and save the user/pass there. "UAC Pass - bypass UAC prompts only for specific programs" may just do that you need. VeeDub_1 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
VeeDub_1 Posted 18 hours ago Author Posted 18 hours ago @argumentum Why """ because I thought I wanted the path, which has spaces, to being enclosed within one set of " I tried just using " instead and the path is now found, but the runas statement still doesn't launch the program. PID = 0. Reason unknown. I'll try UAC Pass. I actually tried using Task Scheduler (without Autoit) and without success before trying the script above. Thanks
VeeDub_1 Posted 18 hours ago Author Posted 18 hours ago @argumentum The site for UAC Pass is broken, I have managed to find a copy on the Net, but I don't have any documentation. Before I started trying to write an autoitscript, I tried using the Task Scheduler and I could not get that to work either. Can I ask what settings that you specify for the Scheduled Task?
argumentum Posted 18 hours ago Posted 18 hours ago Local $sProgram = FileGetShortName("C:\Program Files (x86)\Advanced IP Scanner\advanced_ip_scanner.exe") FileGetShortName() would solve the spaces "problem". But either way, RunAs() did not behave as it used to for me ( thank you M$ ) I'd have to code something and test it out before telling you to do this or that. If you run a task in task scheduler "with highest privileges" it should work. You could rip that part from Control Viewer (mod.). and see if that works for you. Place it in the folder you're having problems with. By default, I don't install anything in the programs folder because is a pain with the permissions and all. .. am looking at Advanced IP Scanner and they have a free download but not a free version for me to test. ( I use my own Ping / discover local IPs ) Now, why would you need to run this as admin ?, is just a port scanner. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
VeeDub_1 Posted 15 hours ago Author Posted 15 hours ago @argumentum Advanced IP Scanner was just a test, as it was something on my laptop in Program Files (x86). The real app of interest is some BMS app which is not widely available and which I do not have installed on my laptop. The app is a 32 bit app running on x64 windows.
ioa747 Posted 11 hours ago Posted 11 hours ago As an example of an x86 application, I chose Au3Info.exe and it worked normally without double quotes even though the path has blank characters Here I must emphasize that at the beginning I entered the 4-digit 'Hello PIN' and it did not work, I had to enter the Admin Password With Windows 11 Pro, Version: 25H2 #AutoIt3Wrapper_UseX64=y #include <AutoItConstants.au3> RunAsAdmin() Func RunAsAdmin() ; Change the username and password to the appropriate values for your system. Local $sUserName = "ElevateUser" Local $sDomain = @ComputerName Local $sPassword = "ElevatePassword" Local $sProgram = "C:\Program Files (x86)\AutoIt3\Au3Info.exe" Local $Status $Status = FileExists($sProgram) ConsoleWrite("Program:" & $sProgram & @CRLF) ConsoleWrite("Status: " & $Status & @CRLF) ; Run Notepad with the window maximized. Notepad is run under the user previously specified. Local $iPID = RunAs($sUserName, $sDomain, $sPassword, $RUN_LOGON_PROFILE, $sProgram, "", @SW_SHOWMAXIMIZED) ConsoleWrite("PID: " & $iPID & @CRLF) EndFunc ;==> RunAsAdmin Output : Program:C:\Program Files (x86)\AutoIt3\Au3Info.exe Status: 1 PID: 6756 VeeDub_1 1 I know that I know nothing
VeeDub_1 Posted 11 hours ago Author Posted 11 hours ago @ioa747 It looks like your computer is not in a domain. I wonder if that is the underlying issue for me. In that the environment I'm operating in is a domain environment and the admin is a domain user. Another key difference is that the user's computer is not 25H2 Thanks for the feedback.
ioa747 Posted 10 hours ago Posted 10 hours ago I think the Status: 0 has to do with the double quotes, for starters, change $RUN_LOGON_PROFILE to $RUN_LOGON_NOPROFILE, as suggested in the help file, which is the light version, to see how it's going as for the Domain, I don't know anything I know that I know nothing
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