How to overcome UAC and install service utility sc.exe?

How to overcome UAC and install service utility sc.exe? The source program is running with administrator rights, but when running

string full_path=install_directory+"myservice.exe";
string command = " create V24UpdateService binpath= \"" + full_path + "\" displayname= \"my_service_display_name\" start= auto";
ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo();
processInfo.FileName = @"C:\Windows\System32\sc.exe";
               processInfo.Arguments = command;
               processInfo.UseShellExecute = true;
               processInfo.Verb = "runas";
               System.Diagnostics.Process.Start(processInfo);

The startup still takes place with limited rights and the service is not installed.

Author: Nicolas Chabanovsky, 2015-06-08

2 answers

If the source process is started with administrator rights, then all child processes are started with the same rights. Your problem is something else.

But for installation, I would recommend using the classes ServiceInstaller and ServiceProcessInstaller. To install it, use the Install method. Note that you can't just call the Install method for both of them - they are dependent on each other and you must either put one of them in the other, or put them both in the other Installer nearby.

One of the disadvantages of this approach is that ServiceProcessInstaller has a problem with passing parameters to the service (it considers any spaces as part of the program name and does not forget to escape them).

Therefore, it is probably worth finding the documentation for installing the service through the registry and doing as they say.

 3
Author: Pavel Mayorov, 2015-06-08 06:08:11

I solved it in a slightly different way, taking the code hence.

In case the link is broken: CreateService and other functions from advapi32.dll via P/Invoke.

 1
Author: lil00, 2015-06-08 10:34:10