Start Application with service
i want to run an application made in c# winform through service.i have done the code but the application does not get started even service successfully gets started and no exception is thrown.
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("starting Kb");
try
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"C:\Program Files (x86)\Invisual E. Inc\KeyboardSetup\keyboard.exe";//Exe Path
myProcess.StartInfo.CreateNoWindow = false;
myProcess.EnableRaisingEvents = true;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
myProcess.Start();
ProcessWindowStyle ws = myProcess.StartInfo.WindowStyle;
if (ws == ProcessWindowStyle.Hidden)
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
eventLog1.WriteEntry("started");
}
catch (Exception c)
{
eventLog1.WriteEntry(c.Message);
}
}
Log file does not show any exceptions.
Purpose is t开发者_运维知识库o start the application at the welcome screen of window so that user can use custom made keyboard .
What operating system? From Vista and beyond you cannot create GUI from services (it's a security flaw and ugly...) There is a user 0 session that shows gui started by services from vista onwards.
Why not create a registry entry and/or startup entry for your app to start when the user who installed your app logs in? Or follow the info here about implementing an interactive service.
A service normally runs under a user other than the logged in user therefore the service doesn't have a desktop available to display any windows form, hence the reason t isn't being displayed.
I think you will need to find another way as although a winforms app can start a service I dont believe it can be done the other way around.
Regards
AJ
精彩评论