c# - Execute several elevated commands in shell (or similar) -
I need to execute several commands with high rights, something like this:
- Start the net myservice (requires admin rights)
- Pure Stop MyService (Admin rights are required)
- / ol>
All this dynamic, e. G. The first line may include proxy settings, including a username and password, or any other amendment in the setting file. (The settings file is in the program folder, the program is provided externally to modify the settings file. The actual information will be recorded through the user GUI.)
I use a lot of CMD The idea is to create a flexible solution. Execution process with redundant studin and stadout but .. It looks like "ryas" (shalexetut is needed) and is redirected - / output are unique. (Also, I saw that redirection and CMD.XA is very difficult to handle. I write my own tasks as a substitute for lidlines, because readline is finally a new line Hope and waits, such as if a command prompt occurs (which means that you are in C: c: \ bla> but no Newline. However, to not know what happens as a result, He Normally writes something normally.)
There are 3 options that I can think of:
- Get a UAC prompt for each command (I will not do it )
- To start a process that is high, it can call whatever she wants -> An additional project (.xa) is required which I want to save, the deployment is more Makes it more difficult (additional file)
- a batch fighter on the fly Make it erect, lift it up. I also want to avoid it, because in that file plain password may contain password information (eg user / password password oyxy). At least I always overwrite its contents and then Be sure to remove it
How to manage it?
I think that you have already diagnosed this issue, and calculating your available options The best option for my mind is to use runas
to create a new high process, and to get that process to work
Other process Should not be executable separately, it is your current executable Programming can be a special command line starting Arguments. Once you are elevating another process, you can definitely use cmd
with the redirect studio / studout. However, why use pure stop / start
instead of the service API? And can you modify the .config
file without starting a separate process?
Comments
Post a Comment