title: Windows Service and Application interaction
body: <p><strong>TL;DR:</strong> <em>I have a service, a gui, and a tray icon. I want to know how to get the tray icon to run on user login/start-up and be able to stop the service and start the gui</em></p>
  
  <p>Some Background Info:</p>
  
  <blockquote>
    <p>I have a windows service I've made that uses a xml file to collect
    files from other computers on my network and store them on the local
    pc (running the service). the xml has some structures called
    'profiles' which have info like FileDestination, LocationToTakeFrom,
    FileTypeToTake, and IsProfileActive...</p>
    
    <p>The service basically takes all the active profiles and every hour
    scans the location for files created within a 1hr window of the
    current date/time on local PC.</p>
    
    <p>My GUI allows the user to make profiles / modify profiles, as
    well as determine which profile(s) should be active for collection. I
    dont want this gui running at all times, so I plan to have a
    systemTrayIcon to allow this GUI to be opened and shutdown.</p>
  </blockquote>
  
  <p>I'm using Visual Studio 2010 .NET 4.0 everything is in C#, I have 1 solution with separate projects(gui and service)</p>
  
  <p>I'm wondering about the following things as far as the System Tray Icon goes:</p>
  
  <p>1) how do I have the icon start on user login (note that this will be distributed via an installer, not just my personal use. so It has to be done via code)</p>
  
  <p>2) Stop a service via sysTrayIcon</p>
  
  <p>3) where to place the SysTrayIcon... do I make a 3rd project? add it in the GUI project? not quite sure here.</p>
  
  <p>4) if SysTrayIcon IS in a seperate project how can I have it create instances of the GUI?
  ie how can I start the GUI application from code in a different project</p>
  
  <p>the project requirements are:</p>
  
  <p>-upon installation the GUI must start, after that the Gui should only be accessed through the tray icon.</p>
  
  <p>-user should be able to stop the service any time via system tray icon</p>