VeeDub_1 Posted 4 hours ago Posted 4 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 4 hours ago Posted 4 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 3 hours ago Posted 3 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 3 hours ago Author Posted 3 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 2 hours ago Author Posted 2 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 2 hours ago Posted 2 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.
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