Run Windows Application From Windows Service?
-
Wednesday, October 18, 2006 1:31 PM
Hi,
I have made a windows service that has a timer checks for a certain time to remind me. Now the time is reached so i want the service to display an alert!!
I have made a windows app that shows the alert but when i run it from the service it runs but not GUI displayed!!!
I can see it runs from the Task Manager but i cant show the form.
So is there any way to dispay i GUI alert from a windows service?
Thanks a lot
All Replies
-
Wednesday, October 18, 2006 2:28 PMModerator
A service should not have a userinterface! You should create a Windows apllication that interacts with the service to do GUI stuff.
To interact between applications use Sockets or Remoting. Here is a list of resources:
- Introduction to TCP client server in C#
- VB.NET TCP Client - Server Socket Communications
- Client Server Multithreading Application
- TinyUDP - Simple UDP Client/Server Components for .NET
- Building Client/Server applications with VB.NET for secure private file sharing
- Real Time TCP/IP using C# - The Code Project - C# Programming
- What is .NET Remoting ?
- Remoting events
- Microsoft .NET Remoting: A Technical Overview
-
Wednesday, October 18, 2006 2:55 PM
Thanks i know how .NET remoting works, but this way i will make the windows service is listening to a certain port and the alert app would be the client, so how the server run the client app??
Client app should be closed all the time until the time for alert so it runs the alert
-
Wednesday, October 18, 2006 3:09 PM
Well, you will probably have to make the client app sit in the background and check in with the service at certain intervals. once the service tells the client app (when it checks in with the service) that there is an alert to display then the app can display the form. there is no way of getting out of it. the client will have to either run in the background or you will have to use the task scheduler service for client app checkins. if you try to run your app from a windows service it will run in the user context of the service. for example. if your windows service runs in the SYSTEM account then if you try to run the GUI from the service. the GUI will display but, only on the SYSTEM account. since you cannot login to the system account it will not work. even if you tried your applcication running under your user account it still will not work as the service would start the GUI under a different session then the one you are logged into. you are left with either letting your client run in the background and checking in with the service or, running it through the task scheduler and check in that way.
Quilnux
-
Wednesday, October 18, 2006 3:25 PM
Hmm i see, thanxxx.
I this is right the way that Antiviruses use, the main app is always running.
I hoped the i could make the load less.
-
Wednesday, October 18, 2006 4:15 PM
window service has a property "Interact with Desktop". Set it to true, Re install the service and see what happens.
I hope this will work!
Best Regards,
-
Wednesday, October 18, 2006 4:19 PM
RizwanSharp wrote: window service has a property "Interact with Desktop". Set it to true, Re install the service and see what happens.
I hope this will work!
Best Regards,
Not sure if this would work but if so make sure you have the user account the service uses to be the user account you want to see the app window from. this would also make the application only work for 1 user, the one that the service runs as.
-
Wednesday, October 18, 2006 4:39 PM
Thanks RizwanSharp,
You are a smart, i get now out of this complexity if .net remoting or any other solutions, it worked fine for all users existing.
-
Wednesday, January 31, 2007 5:36 AM
Hello Mr TheMaj0r
I have doubts on the same topic,But I am new to .NET and I don't have any idea abt .NET remoting ,Can u plz post code How to run windows application from windows service,
or Plz give me step by step process How to do it ,I hope u will understand my Request,I will be waiting for u r replay
Regards
GovardhanReddy
-
Thursday, February 08, 2007 10:29 AMHello Mr TheMaj0r
I have a problem on the same topic. But I am beginner on .NET and I don't have any about .NET remoting. Can u please post code? How to run windows application from windows service?
or Plz give me step by step process. How to do it ,I hope u will understand my Request and help me, Can you send me your code? my email : aagii_jp@yahoo.com
I will be waiting for u r reply...
Regards aagii -
Saturday, February 17, 2007 4:00 PM
Sorry guys for being late !!
if you want windows service to call or run windows app so u need to use
System.Diagnostics.Process.Start(appName , args);
and this is like you run the app with command prompt, but the problem is that the win service doesnt support GUI so you have to change the proberty of the win serv interact with desktop to true, this will allow win serv to run GUI apps.
Regards
-
Friday, May 18, 2007 8:33 AM
Hi major,
Below is the code which we use to print files(can be .pdf,txt,doc ).
SetDefaultPrinter("\\01hw111683\\ZoneThree");
ServProcess.StartInfo.CreateNoWindow =
true;ServProcess.StartInfo.FileName =
"c:\\Projects\\test.txt";ServProcess.StartInfo.Verb=
"Print";ServProcess.StartInfo.UseShellExecute =
true;ServProcess.Start();
SetDefaultPrinter is an api to set default printer. rest i guess u can understand. The problem is i cant change the property to run on local system account(client requirement) so i cant make it interactive with desktop. I have looked on net but no alternates are there. Its like microsoft dont allow access to printer from windows service at all. I am so busted. Its kind of urgent. Please help.
-
Friday, May 18, 2007 8:39 AM
Hi Mr. PJ. van de Sande,
Below is the code which we use to print files(can be .pdf,txt,doc ).
SetDefaultPrinter("\\01hw111683\\ZoneThree");
ServProcess.StartInfo.CreateNoWindow =
true;ServProcess.StartInfo.FileName =
"c:\\Projects\\test.txt";ServProcess.StartInfo.Verb=
"Print";ServProcess.StartInfo.UseShellExecute =
true;ServProcess.Start();
SetDefaultPrinter is an api to set default printer. rest i guess u can understand. The problem is i cant change the property to run on local system account(client requirement) so i cant make it interactive with desktop. I have looked on net but no alternates are there. Its like microsoft dont allow access to printer from windows service at all. I am so busted. Its kind of urgent. Please help.
-
Saturday, May 03, 2008 9:19 AM
guys m sorry i'm too late to post this question
I'm having same kinda issue, that i need to call the log off through the windows service.
what i understood is that if you set the property "interact with desktop" to true, the it would work.
but problem is that i canot find the property in my windows service, Vs 2005 .NET 2.0, VB.NETBut currently it calls the function to logoff the operating system but nothing happens,
Same functionality works absolutly fine when I run my program as windows application rather than windows service.
any help is appreciated.
regard - raheel
-
Friday, February 12, 2010 5:43 AMWrite an event log and check what error is coming from the Windows serviceFirst of all the onStart() should return to the OS after finishing the work. It is a precondition of Windows Services.So I dont think u can call the logoff in onStart()...Better to check wt error comes in the event log..

