According to the comments to the question you want to run a standard desktop app, built with WinForms, not a service, that starts before the user has logged on.
This is not possible. What you need is a service.
Question
How can i start a windows forms application before log on to windows? Is is possible to start a windows forms application before log on to windows? If it's not, do i have a chance to start a windows service before log on and invoke a windows forms application from the service that is already started before log on?
Solution
According to the comments to the question you want to run a standard desktop app, built with WinForms, not a service, that starts before the user has logged on.
This is not possible. What you need is a service.
OTHER TIPS
Very basic, but should give you the gist. You also need to create a ServiceProcessInstaller
for it (along with making a call to installutil
).
public class WinFormHostService : System.ServiceProcess.ServiceBase
{
[STAThread]
public static void Main()
{
System.ServiceProcess.ServiceBase.Run(new WinFormHostService());
}
protected Process winFormsProcess;
public WinFormHostService()
{
this.ServiceName = "WinForm Host Service";
this.AutoLog = true;
}
protected override void OnStart(String[] args)
{
this.winFormsProcess = new Process();
try
{
this.winFormsProcess.UseShellExecute = false;
this.winFormsProcess.FileName = @"C:\Program Files\MyApp\MyApp.exe";
this.winFormsProcess.CreateNoWindow = true;
this.winFormsProcess.Start();
}
catch (Exception ex)
{
// unable to start process
}
}
}
This is basically like hosting a WCF service from a windows service, so if you need more details look up "WCF windows service host" (or alike) and see how that's done. Same premise, you're just using a Process
instead.