Jump to content

Recommended Posts

Posted

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)

#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

Posted

@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

Posted

@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?

Posted
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.
autoit_scripter_blue_userbar.png

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