简体   繁体   中英

How to start a process from a Windows Service

I'm working on my own anti-scriptmalware scanner ( SharpDefender ) and it of course requires Administrator for some stuff. I've been searching on the Internet how i can start it as admin without UAC disturbing the user, and as a result came the Windows Service. So after that I wanted to create a Windows Service for my application but it seems it cannot start the .exe of my program. I've checked the option that the service interact with the desktop.

Is there even a possibility to start a process from a code like this:

Process sdef = new Process();
sdef.StartInfo.Filename = locApp + "\\sdefender.exe";
sdef.StartInfo.Arguments = "-hidden";
sdef.Start();

Am I doing something wrong or is there an other way to start the executable with elevated rights?

I have a service that runs apps at a predefined time (much like a scheduled task, but running in the server without needing a logged session).

What I have is, in the OnStart method, a call to a private method (StartService), which starts a new thread (WorkerFunction). In that thread I have the following code to start the application:

Process _proc = Process.Start ( _Program, _Arguments );

Hope this helps.

Sincerely,

José Mira

You can choose who your service is logged in as. So you should be able to have your service running under an admin account, so any action performed by it should already have that access.

Here is a link that talks about doing this within your code. Or, like me, you can just open Services.exe, find your process, right-click and select properties, then go in the Log On tab and put in the info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM