1

I am creating a simple attendance application that will have a simple interface (with two input boxes and a submit button) and a windows service running in background.

The Idea is to capture login/logout events and calculate hours accordingly. The issue is how to create a windows service which can run on background but also have an interface for users to add their identification?

Thanks

GeForce
  • 90
  • 1
  • 8
  • Why you need a Windows Service ? – Kurubaran Sep 16 '13 at 06:08
  • To make sure it starts with windows and is available for all users, and can capture login/logout events ? – GeForce Sep 16 '13 at 06:12
  • 1
    I would suggest decoupling the UI from the service and then communicating between the UI and the service using some inter-process communication mechanism. Windows Services are not allowed UI other than running in a controlled window which is not user friendly. See here: http://stackoverflow.com/questions/53232/how-can-i-run-a-windows-gui-application-on-as-a-service – acarlon Sep 16 '13 at 06:15

1 Answers1

0

You don't need a windows service for that. Having a windows service which interact with UI will be complicated task. You can't directly open UI and show it on user desktop from windows service as it will result in security risks.

I would suggest you to create a Windows app and execute it on windows startup. You can easily call your exe on windows startup. Just set your application name and exe path to the following register entry which will be executed on OS startup.

Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
key.SetValue("Your Application Name", @"Your application path.exe");

EDIT

Getting the currently logged in user name

string loggedInUser = Environment.UserName;
Kurubaran
  • 8,696
  • 5
  • 43
  • 65