Tyrrrz / CliWrap

Library for running command-line processes
MIT License
4.32k stars 264 forks source link

RunAs functionality #174

Closed mobycorp closed 1 year ago

mobycorp commented 1 year ago

Details

Greetings,

First off, I love CliWrap! I have used it now in several of my projects. Thanks for your efforts! You've really done a great job with this project!

I have a need to run some PowerShell scripts that need to be run with admin privilege. I do not see anywhere in your APIs where I can specify the Verb parameter on the process object. Am I missing it or do I need to request this feature? If it is there, I'd love to know how to run a process as administrator.

Also, I check the progress that Ukraine is making against the Russian aggressors. I read with joy whenever I see that Russia is in retreat, having their helicopters and aircraft knocked from the skies, and seeing the Russian cowards getting their asses kicked! All of Ukraine is in my thoughts and prayers, my friend!

Cheers, Steve Miller

Tyrrrz commented 1 year ago

Hey there.

Unfortunately, running as admin is only possible via shell execute. This means that we won't be able to gain access to the process's output streams or do other things like kill the process on cancellation. This is a security limitation that prevents non-elevated processes from accessing information from elevated processes. In that state, 90% of CliWrap's functionality becomes effectively useless. Because of this, your best bet is to offer a prompt for the user to relaunch your own application with admin privileges, and then use CliWrap as you would normally to run other processes after that.

mobycorp commented 1 year ago

Oleksii,

Thanks for your rapid response! The fact that I was unable to find the strings, "verb", "runas", and admin in your source code, I figured as much. Oh well. I can simply code a x = new ProcessStartInfo with the appropriate arguments and do it the old fashioned way!! 😇

Thanks again! Steve

On Thu, Nov 10, 2022 at 4:07 PM Oleksii Holub @.***> wrote:

Hey there.

Unfortunately, running as admin is only possible via shell execute. This means that we won't be able to gain access to the process's output streams or be able to do other things like kill the process on cancellation. This is a security limitation that prevents non-elevated processes from accessing information from elevated processes. Because of this, your best bet is to offer a prompt for the user to relaunch your own application with admin privileges, and then use CliWrap as you would normally to run other processes after that.

— Reply to this email directly, view it on GitHub https://github.com/Tyrrrz/CliWrap/issues/174#issuecomment-1311061879, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOPRYYJJ4KVFLWSHFROMNQTWHWE47ANCNFSM6AAAAAAR5CX32M . You are receiving this because you authored the thread.Message ID: @.***>

Tyrrrz commented 1 year ago

Cheers!