Jump to content

How to run not elevated program ?


Go to solution Solved by Gianni,

Recommended Posts

Posted (edited)

in some compiled script I use:

#RequireAdmin

This particular program have to run other exe file which normally should be easy by using:

ShellExecute() or Run()

But I need to run this External.exe as non elevated instance.

Anybody know how to do that ?

edit:
of course without using RunAs() as I do not want to provide login and password, I mean it should run on currently logged user credentials, just not in elevated mode.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Here's a thread that talked about the same issue as you are: 

The outcome was basically to have a script running that was admin, was not admin, and have each individually launch applications as you needed their specific permission level. 

There's also this topic linked, does this meet your needs? (Just kidding, unless someone has a copy, the site that the file/UDF was hosted on is no longer available).

Another option could possibly be to use the Task Scheduler, though that seems like a pretty involved method, and RunAs would likely be simpler, but either likely require password.

 

Edit: This may also be of interest, since it has a cmd option: https://superuser.com/questions/171917/force-a-program-to-run-without-administrator-privileges-or-uac

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Posted

There is a simple way using the "__COMPAT_LAYER" environment variable,  but it does not work with all programs.

Example here, if you want to run regedit without privileges

EnvSet("__COMPAT_LAYER", "RunAsInvoker")
Run("regedit.exe")

Run application without elevation ('Run As Administrator') (nirsoft.net)

 

  • 2 weeks later...
Posted (edited)

Thanks but this still not works.

I attach main.au3 and test.au3, to test what I mean just simply:
compile them both and run main.exe

You will see that test.exe msgbox shows IsAdmin() = 1

My intention is to get IsAdmin() = 0 but to be more specific by running main.exe

 

main.au3Fetching info... test.au3Fetching info...

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 3/27/2023 at 4:51 PM, argumentum said:
cmd /min /C "set __COMPAT_LAYER=RUNASINVOKER && start "" "YourExe.exe"

I use this and works quite fine for me.

Expand  

This will be fine if you run CMD with reduced privileges, but try to start CMD with Admin privileges .

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 3/27/2023 at 8:51 PM, mistersquirrle said:

Just a little followup to @Giannis answer, 0x20000 is a "Basic User", and you can see what's available by running this in cmd:

runas /showtrustlevels

Here's some other examples of it: https://stackoverflow.com/questions/20218076/batch-file-drop-elevated-privileges-run-a-command-as-original-user

Expand  

I was trying to use this and I got this problem:

https://superuser.com/questions/1749696/parameter-is-incorrect-when-using-runas-with-trustlevel-after-windows-11-22h2

so I use:

  Quote

runas /trustlevel:0x20000 /machine:x86 test.exe

Expand  

and I get:

  Quote

The image file c:\1\test.exe is valid, but it is for a different type of computer than the current one

Expand  

and solution was to add directive to test.au3:

#AutoIt3Wrapper_UseX64=n
MsgBox(0, "testing:", 'IsAdmin() = ' & IsAdmin())

and the main.au3:

#RequireAdmin
Run('runas /trustlevel:0x20000 /machine:x86 test.exe')

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

on some computers I have hit an issue:

So I modified main.au3 to this form:

#RequireAdmin
#include <MsgBoxConstants.au3>

; https://superuser.com/a/1755207/1049106

_Example()
Func _Example()
    Local $s_EXE_Path = '"' & @ScriptDir & '\test.exe"'
    ConsoleWrite("! " & @CPUArch & @CRLF)
    ConsoleWrite("! " & @OSArch & @CRLF)
    ConsoleWrite("! " & @OSType & @CRLF)
    ConsoleWrite("! " & @OSVersion & @CRLF)
    ConsoleWrite("! " & @OSBuild & @CRLF)
    ConsoleWrite("! " & @OSVersion & @CRLF)
    ConsoleWrite("! " & @OSServicePack & @CRLF)

    ConsoleWrite($s_EXE_Path & @CRLF)

    MsgBox($MB_TOPMOST, "", 1)
    Local $iResult1 = Run('runas /trustlevel:0x20000 /machine:x86 ' & $s_EXE_Path, @ScriptDir, @SW_HIDE)
    ConsoleWrite("! $iResult1  = " & $iResult1 & @CRLF)

    MsgBox($MB_TOPMOST, "", 2)
    Local $iResult2 = Run('runas /trustlevel:0x20000 ' & $s_EXE_Path, @ScriptDir, @SW_HIDE)
    ConsoleWrite("! $iResult2  = " & $iResult2 & @CRLF)
    MsgBox($MB_TOPMOST, "", 3)

EndFunc   ;==>_Example

 

And I notice that some computers do not like /machine:x86 option

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Ran into this problem with a script. A workaround is to create a shortcut and launch that. 
 

If FileExists("C:\Program Files\Google\Chrome\Application\chrome.exe") Then FileCreateShortcut ("C:\Program Files\Google\Chrome\Application\chrome.exe",@DesktopDir &"\test.lnk","C:\Program Files\Google\Chrome\Application","http://example.com")

Run("explorer.exe "&@DesktopDir&"\test.lnk")


    

Posted (edited)

_RunWithReducedPrivileges does have a caveat: If you launch an app as a different user, any child processes run via _RunWithReducedPrivileges is launched by the logged in user instead of the user of the parent process.

 

When I run 

runas /trustlevel:0x20000 someapp.exe

from an elevated application and look in Task manager, the resulting process is says it's elevated. Unless there's something funky with my PC, the /trustlevel argument doesn't seem to work.

Edited by rsn
Posted
  On 4/5/2023 at 1:53 PM, rsn said:

the resulting process is says it's elevated.

Expand  

Which windows ? 11 ? Which exact version ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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