topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday October 3, 2024, 12:59 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
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:
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 12, 2018, 10:09 PM by KodeZwerg »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
I attached a testing tool that help quick identify status.
Screenshot - non-elevated.jpg[Solved by 4wd] Tool to let me execute Programs with chooseable permission [Ty!] This i want to achive
Screenshot - elevated.jpg[Solved by 4wd] Tool to let me execute Programs with chooseable permission [Ty!] This is what happen

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #2 on: August 12, 2018, 03:10 PM »
Still no answer, i guess it is impossible than.

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

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #4 on: August 12, 2018, 06:17 PM »
Thank you for reply, sadly it doesnt do the job.
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
    • View Profile
    • Donate to Member
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #5 on: August 12, 2018, 07:05 PM »
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Tool to let me execute Programs with chooseable Execution-Rights
« Reply #6 on: August 12, 2018, 09:09 PM »
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 [Select]
  1. <#
  2.   Run-NonEl.ps1
  3. #>
  4.  
  5. function Run-NonElevated( [string] $cmd ) {
  6.     $task_name = "Run-NonElevated-$(New-Guid)"
  7.     schtasks /Create /RU $Env:USERNAME /TN $task_name /SC ONCE /ST 00:00 /F /TR $cmd
  8.     schtasks /run /tn $task_name
  9.     schtasks /delete /F /tn $task_name
  10. }
  11.  
  12. 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[Solved by 4wd] Tool to let me execute Programs with chooseable permission [Ty!]


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[Solved by 4wd] Tool to let me execute Programs with chooseable permission [Ty!]

So it appears to work.
« Last Edit: August 12, 2018, 09:26 PM by 4wd »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
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!