DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: [Solved by 4wd] Tool to let me execute Programs with chooseable permission [Ty!]  (Read 21,393 times)

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Hello Coders!

I have the following problem that i somehow can not solve on my own due lack of experience.
I have written a Program that is executed with Admin-Rights.
From that program i run other programs, but i do not want that others get same execution-rights as my own program has.

So my wish would be a little App-Starter where i have an command-line interface like
Parameter 1 = "Application Path + Name" (<- this will be executed)
Parameter 2 = "additional parameters" (<- this could be parsed to Parameter 1 if it helps)
Parameter 3 = True/False "Run As Admin/Run not as Admin" (<- this is most important)

What i tried on my own was a creating a batch file:
Code
cmd /min /C "set __COMPAT_LAYER=RUNASINVOKER && start "" %1"
but target is executed with same Rights that my Application got.

(a wish would be some Delphi Snippet with such ability, but anything that does this job is more than welcomed!)

Can some more experienced help me please?
« Last Edit: August 13, 2018, 03:09 AM by KodeZwerg »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
I attached a testing tool that help quick identify status.
Screenshot - non-elevated.jpg This i want to achive
Screenshot - elevated.jpg This is what happen

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #2 on: August 12, 2018, 08:10 PM »
Still no answer, i guess it is impossible than.

@Admin, feel free to delete/remove thread, thanks.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #3 on: August 12, 2018, 10:01 PM »
Does this help?

https://stackoverflow.com/questions/20218076/batch-file-drop-elevated-privileges-run-a-command-as-original-user
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #4 on: August 12, 2018, 11:17 PM »
Thank you for reply, sadly it doesnt do the job.
Quote
IsAdministrator = False
IsAdministratorAccount = True
IsUACEnabled = True
IsElevated = True
Only the "IsAdministrator" Flag will be set to false, i badly need "IsElevated" as False.
Or with other words, thank you for helping to terminate one flag, just one left to go and i am done  :Thmbsup:

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #5 on: August 13, 2018, 12:05 AM »
Sorry my fault, you have no testing Application, just a resulting Application from Post #2.
I've attached a Demo Application that execute "Batch.bat".
Two modes in Demo are supported, the first called forced privileges, in that mode i want to achieve "IsElevated = False".

Three non-working examples included in Batch.bat.

If someone find out how, please let me know! Thank you for support!
You will need those files:
RunAsTester.exe (from Post #2)
RunAsDemo.exe (inside this archive)
Batch.bat (inside this archive)

Please edit Path inside Batch.bat to your Filesystem before loading RunAsDemo.exe.
The RunAsDemo.exe will not require admin privileges at start, all managed from within Demo.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #6 on: August 13, 2018, 02:09 AM »
It seems that the recommended way to start a non-elevated command from an elevated session is to use the Task Scheduler:

From here:
Code: ( powershell)
<#
  Run-NonEl.ps1
#>

function Run-NonElevated( [string] $cmd ) {
    $task_name = "Run-NonElevated-$(New-Guid)"
    schtasks /Create /RU $Env:USERNAME /TN $task_name /SC ONCE /ST 00:00 /F /TR $cmd
    schtasks /run /tn $task_name
    schtasks /delete /F /tn $task_name
}

Run-NonElevated "%WINDIR%\System32\cmd.exe /C K:\RunAsTester.exe"

Which gives this from an elevated PowerShell console:
.\Run-NonEl.ps1
2018-08-13 12_07_45-RunAs Test.png


And the following from an elevated PowerShell console:
C:\Windows\System32\cmd.exe /C K:\RunAsTester.exe
2018-08-13 12_11_07-RunAs Test.png

So it appears to work.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: August 13, 2018, 02:26 AM by 4wd »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Hello 4wd,

in reply to your last Post, yeah, this sound reproducable to me and will solve my issue with Windows and privileges.
A new hunt for me begun to figure out "how-to" delphi that, thanks alot for your help!

Original address: https://www.donationcoder.com/forum/index.php?topic=45907.0