Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I created a windows service with Process.start(filepath) in it. But it is neither working nor showing any errors.

I tried BackgroundWorker with DoWorkEventHandler delegate to start the process. But I failed to start the process.

I also tried with ProcessStartInfo and UseShellExecute as false but it is not working.

What I have tried:

Process prs = new Process();
string strAppPath;
strAppPath = @"C:\CMT\Debug\testing.exe";
prs = Process.Start(strAppPath);
prs.WaitForExit();
base.Stop();
Posted
Updated 19-Aug-19 0:48am
v2
Comments
Maciej Los 19-Aug-19 6:29am    
"it is not working" is not informative at all. Can you be more specific and provide more details?
Dave Kreskowiak 19-Aug-19 10:48am    
It's simple. Don't do it.

Do so is considered a security risk. Any "solution" (read: workaround) you implement to do this runs the risk of not working in a future release of Windows. Security around doing this has been tightened, and tightened, and tightened again.

By the way, your code didn't fail. It launched the process on the service desktop, not the users desktop. The app is running, you just can't see it or interact with it.

Windows services cannot have a user interface, nor can they start or run any application which does have a user interface - because a user interface requires a user to be logged in, and services can run without a user (because they don't run under the user account; they can be run when the OS boots up and never have a login occur).

Basically, if your app has a user interface, be it a GUI or a console, a service cannot start it at all.
 
Share this answer
 
Comments
Maciej Los 19-Aug-19 7:13am    
5ed!
Please, read this: .net - How can I run an EXE program from a Windows Service using C#? - Stack Overflow[^]

The most important information is:
Quote:
Windows Services cannot start additional applications because they are not running in the context of any particular user. Unlike regular Windows applications, services are now run in an isolated session and are prohibited from interacting with a user or the desktop.


Follow the link to find 2 workarounds:
1) create a standard Windows application instead of a service,
or
2) create console application, which will prevent Windows from blocking the creation of process, because it will no longer request that a Console window be created
 
Share this answer
 
With newer Windows versions you can not run Windows Forms applications from a service, Microsoft blocked this a long time ago.
You might be interested in Run any WinForms application as a Windows Service[^]
 
Share this answer
 
v2
Comments
Zalak Parikh 19-Aug-19 6:40am    
I only want to start any of system program executable files, like notepad.exe, cmd.exe, creo.exe, etc., not windows forms applications.
RickZeeland 19-Aug-19 6:43am    
Sorry notepad.exe is also a Windows forms application !
Zalak Parikh 19-Aug-19 7:30am    
May be you are right. but I found notepad.exe in background process.
F-ES Sitecore 19-Aug-19 10:40am    
The process starts but it has no access to the interactive desktop so you can't see it or interact with it.
RickZeeland 19-Aug-19 11:31am    
Indeed, that's the more correct explanation :)
I found the solution.

use below link

https://social.msdn.microsoft.com/Forums/vstudio/en-US/990e7c4a-afa7-47aa-b9a6-d5b6beb19f41/call-a-program-via-windows-service?forum=csharpgeneral
 
Share this answer
 
Comments
Dave Kreskowiak 19-Aug-19 10:46am    
How long is it going to be before MS slams the door shut on this "workaround" too?

Launching user processes from a non-user session is a security risk. Always has been, always will be.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900