Windows/UAC - Launch another program not as administrator?
Windows/UAC - Launch another program not as administrator?
does anyone have a way to run a program from an elevated user (ie: program "run as" administrator) ?
If you use runprogram() or shellexecute_(); it inherits the elevation, what I need is for the new program to not run as administrator despite being launched from an elevated program...
If you use runprogram() or shellexecute_(); it inherits the elevation, what I need is for the new program to not run as administrator despite being launched from an elevated program...
Re: Windows/UAC - Launch another program not as administrator?
Hi jassing
Run as Invoker
See which one will suit you
And I think NirSoft has some tool to do it
Run as Invoker
See which one will suit you
And I think NirSoft has some tool to do it
Code: Select all
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\forcerunasinvoker]
@="Run without privilege elevation"
[HKEY_CLASSES_ROOT\*\shell\forcerunasinvoker\command]
@="cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"%1\"\"
;************************************************************************
cmd /min /C "set __COMPAT_LAYER=RUNASINVOKER && start "" %1"
;****************************** Compatibility Shim ******************************************
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\example\\application.exe"="RunAsInvoker"
Egypt my love
Re: Windows/UAC - Launch another program not as administrator?
Thank you, Rashad - Using compatibility layer in a batch file doesn't actually do much - it does not "de-elevate" (I've tried it)
Compile to exe.
Then run it using the compat_layer from an "as administrator" exe - it's still 'admin' and the compat layer is set....
Code: Select all
v$ = #CRLF$+GetEnvironmentVariable("__COMPAT_LAYER")
If IsUserAnAdmin_()
MessageRequester("test","admin"+v$)
Else
MessageRequester("test","user"+v$)
EndIf
Then run it using the compat_layer from an "as administrator" exe - it's still 'admin' and the compat layer is set....
Re: Windows/UAC - Launch another program not as administrator?
Just tested NirSoft utility with your example compiled as Admin
It worked as expected
No admin
It worked as expected

No admin
Egypt my love
Re: Windows/UAC - Launch another program not as administrator?
I'll have a look at nirsoft -- sorry, I was focused on the compat layer...RASHAD wrote: Mon May 15, 2023 7:55 am Just tested NirSoft utility with your example compiled as Admin
It worked as expected![]()
No admin
Re: Windows/UAC - Launch another program not as administrator?
Is there a way to do this without a third-party tool like the one from NirSoft? It's not professional to rely on someone else's tool for your product.
My scenario: I'm logged in as a standard user, but run my exe with admin rights (I enter the UAC password). My app then needs to launch another exe as standard, but currently can't because the launched app inherits admin rights (as Jassing noted).
My scenario: I'm logged in as a standard user, but run my exe with admin rights (I enter the UAC password). My app then needs to launch another exe as standard, but currently can't because the launched app inherits admin rights (as Jassing noted).
Re: Windows/UAC - Launch another program not as administrator?
Hi BarryG,
AFAIK there isn't a way to de-elevate a process, but you can duplicate the token of an existing process and use it to run an executable without elevation.
Yes, but it requires compiling a separate executable...BarryG wrote:Is there a way to do this without a third-party tool like the one from NirSoft?
AFAIK there isn't a way to de-elevate a process, but you can duplicate the token of an existing process and use it to run an executable without elevation.
Last edited by JHPJHP on Sat Oct 19, 2024 1:29 am, edited 5 times in total.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: Windows/UAC - Launch another program not as administrator?
Microsoft's Raymond Chen says it's not possible from an elevated process -> https://devblogs.microsoft.com/oldnewth ... 0/?p=94735
So I don't know how NirSoft is doing it. (Having said that, I didn't try it with my scenario; I'm just going by the comments above).
Re: Windows/UAC - Launch another program not as administrator?
Hi BarryG,
Since you didn't mention it, I'm guessing the solution I offered didn't interest you; my previous post has been updated.
The result is the same as described by Raymond Chen in the article you referenced: Is RunAsInvoker a secret, even higher UAC setting?
• Simple manifest override using compatibility options set from a command shell: What does '__COMPAT_LAYER' actually do?
• In PureBasic terms, it overrides the Compiler Option "Request Administrator mode" before the application is executed.
Since you didn't mention it, I'm guessing the solution I offered didn't interest you; my previous post has been updated.
Unfortunately, if you're referring to the command-line tool RunWithoutElevation, it cannot de-elevate a process executed from one with elevation.BarryG wrote:So I don't know how NirSoft is doing it.
The result is the same as described by Raymond Chen in the article you referenced: Is RunAsInvoker a secret, even higher UAC setting?
• Simple manifest override using compatibility options set from a command shell: What does '__COMPAT_LAYER' actually do?
• In PureBasic terms, it overrides the Compiler Option "Request Administrator mode" before the application is executed.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: Windows/UAC - Launch another program not as administrator?
No, it's not like that. I read everything but don't always test or do any suggestions at the time; and then sometimes I just post further musings about it. Probably a bad idea, in hindsight. Don't take it the wrong way.JHPJHP wrote: Tue Oct 15, 2024 10:57 pmSince you didn't mention it, I'm guessing the solution I offered didn't interest you; my previous post has been updated.
I just took at look at your "RunExeAsSYSTEM" source but even though I ran it elevated and then ran another exe with the SYSTEM option, it doesn't show SYSTEM in Task Manager for it? I'm probably using it wrong, though.


Re: Windows/UAC - Launch another program not as administrator?
Hi BarryG.
From the image you posted I'm able to determine that it's not a recent version of the program.
• While Run Executable as SYSTEM uses some of the same scripts, it's not what I was referring to.
• I've created an include file that does exactly what you're requesting, initiated from a single Procedure call.
• As was previously mentioned, a separate compiled executable is part of the package; executable script included.
Sent you a PM with the following link: RunProcess.zip
➤ Each example can do what you're requesting:
• RPaU.pb: Run Process as User (current logged-in user account).
• SICP.pb: Start Interactive Client Process (requires a username and password to an existing user account).
Each example opens two command prompt windows:
1. Display User, Group and Privilege information for SYSTEM.
• Elevated process executing a program as SYSTEM.
2. Display User, Group and Privilege information for a user account.
• Elevated process executing a program in a non-elevated process.
The first Procedure call is not needed, it's only there to demonstrate an elevated process to SYSTEM.
From the image you posted I'm able to determine that it's not a recent version of the program.
• While Run Executable as SYSTEM uses some of the same scripts, it's not what I was referring to.
• I've created an include file that does exactly what you're requesting, initiated from a single Procedure call.
• As was previously mentioned, a separate compiled executable is part of the package; executable script included.
Sent you a PM with the following link: RunProcess.zip
➤ Each example can do what you're requesting:
• RPaU.pb: Run Process as User (current logged-in user account).
• SICP.pb: Start Interactive Client Process (requires a username and password to an existing user account).
Each example opens two command prompt windows:
1. Display User, Group and Privilege information for SYSTEM.
• Elevated process executing a program as SYSTEM.
2. Display User, Group and Privilege information for a user account.
• Elevated process executing a program in a non-elevated process.
The first Procedure call is not needed, it's only there to demonstrate an elevated process to SYSTEM.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: Windows/UAC - Launch another program not as administrator?
I have an old version of RunExeAsSYSTEM from February 2023, compiled in 64 bit, it seems to work well here win 10 x64


Last edited by ChrisR on Thu Oct 17, 2024 3:23 pm, edited 1 time in total.
Re: Windows/UAC - Launch another program not as administrator?
Why not do it the other way around?
Run as User initially, then run a 2nd process of the same program as Admin.
Then the 2 processes have to communicate with each other...
Run as User initially, then run a 2nd process of the same program as Admin.
Then the 2 processes have to communicate with each other...
Code: Select all
Procedure RunAsAdmin(ProgramName$, Parameters$ = "", WorkingDirectory$ = "")
Protected shExecInfo.SHELLEXECUTEINFO
With shExecInfo
\cbSize = SizeOf(SHELLEXECUTEINFO)
\lpVerb = @"runas"
\lpFile = @ProgramName$
\lpParameters = @Parameters$
\lpDirectory = @WorkingDirectory$
\nShow = #SW_NORMAL
EndWith
ProcedureReturn ShellExecuteEx_(shExecInfo)
EndProcedure
If Not IsUserAnAdmin_()
If Not RunAsAdmin(ProgramFilename())
End
EndIf
EndIf
If IsUserAnAdmin_()
MessageRequester("Information", "ProcessID: " + Str(GetCurrentProcessId_()) + " Run as Admin")
Else
MessageRequester("Information", "ProcessID: " + Str(GetCurrentProcessId_()) + " Run as User")
EndIf
Re: Windows/UAC - Launch another program not as administrator?
Hi ChrisR,
Thank you for confirming the older version of Run Executable as SYSTEM is working as it should. It supports my concern that the security settings BarryG has set may not be compatible with the code I provided. That's not to say that either thing is wrong, just that they don't work together. Sometimes you need to limit security, and Microsoft justifiably doesn't allow user accounts with lower security, access to elevated privileges.
Your second post is smart out-of-the-box thinking, something that has helped make IceDesign GUI Designer a success.
BarryG can determine if it's a viable solution, but in all the times where my program required elevated privileges but still needed access to a local user account, this would not have worked. Take for instance a Windows service where the process runs as SYSTEM but required access to a local user account.
Thank you for confirming the older version of Run Executable as SYSTEM is working as it should. It supports my concern that the security settings BarryG has set may not be compatible with the code I provided. That's not to say that either thing is wrong, just that they don't work together. Sometimes you need to limit security, and Microsoft justifiably doesn't allow user accounts with lower security, access to elevated privileges.
Your second post is smart out-of-the-box thinking, something that has helped make IceDesign GUI Designer a success.
BarryG can determine if it's a viable solution, but in all the times where my program required elevated privileges but still needed access to a local user account, this would not have worked. Take for instance a Windows service where the process runs as SYSTEM but required access to a local user account.
Last edited by JHPJHP on Sat Oct 19, 2024 1:33 am, edited 2 times in total.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: Windows/UAC - Launch another program not as administrator?
@JHPJHP: I'll do more testing tonight. (Got your PM, too).