Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service starting a process wont show GUI C#

Tags:

People also ask

How can a Windows service execute a GUI application?

The service communicates with the GUI application to tell it when to display the GUI. The application communicates the results of the user interaction back to the service so that the service can take the appropriate action.

Can Windows service have GUI?

Windows services cannot have GUIs, so you will need to either get rid of the GUI or separate your application into two pieces - a service with no UI, and a "controller" application.

Can a Windows service launch an application?

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.

How do I view the GUI in Visual Studio?

Typically you would just double click your form name (form1. cs) because then your design view will pop up or hit Shift+F7 or rightclick --> view designer. Then just double click whatever tools you have on your form (like a button) and it will automatically go to the button code.


Hey, I am trying to get a service to start my program but it isn't showing the GUI. The process starts but nothing is shown. I have tried enabling 'Allow service to interact with desktop' but that still isn't working. My program is a computer locking device to stop unauthorised users from accessing the computer. I am running windows 7 with a 64 bit OS.

Here is the code for my service:

        protected override void OnStart(string[] args)
    {
        Process p = new Process();
        p.StartInfo.FileName = "notepad.exe";
        p.Start();

        FileStream fs = new FileStream(@"C:\Users\David\Documents\Visual Studio 2010\Projects\LockPCService\LockPCService\bin\Debug\ServiceLog.dj",
        FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter m_streamWriter = new StreamWriter(fs);
        m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
        m_streamWriter.WriteLine(" LockPCService: Service Started " + DateTime.Now + "\n" + "\n");
        m_streamWriter.Flush();
        m_streamWriter.Close();
    }

    protected override void OnStop()
    {
        FileStream fs = new FileStream(@"C:\Users\David\Documents\Visual Studio 2010\Projects\LockPCService\LockPCService\bin\Debug\ServiceLog.dj",
        FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter m_streamWriter = new StreamWriter(fs);
        m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
        m_streamWriter.WriteLine(" LockPCService: Service Stopped " + DateTime.Now + "\n"); m_streamWriter.Flush();
        m_streamWriter.Close();
    }

To try and get the service working I am using notepad.exe. When I look at the processes notepad is running but there is no GUI. Also the ServiceLog is there and working each time I run it.

Any ideas on why this isn't working?

Thanks.