7

I wonder is it possible to run my application before login on windows.? Its actually a WinForm application(Preferably other than Windows service).

I mean my application must be running even before log in and it should sit on System Tray from which I can "show" or open Interface for user.

Dark Knight
  • 3,507
  • 8
  • 35
  • 44
  • 6
    Why not make it a service? – Lasse V. Karlsen May 05 '11 at 11:22
  • 1
    Services *shouldn't* interact with the desktop which is probably a bad thing for a winform app ... – Russ Clarke May 05 '11 at 11:25
  • You can't feasibly have your application start up before login if it's not a service. And yet, a WinForms app can't be a service. So... – BoltClock May 05 '11 at 11:26
  • hmm, what happens if you do bring up a process/window inside desktop session before logon? Is it at all possible to gain control at that point? – mmix May 05 '11 at 11:36
  • application has to send some data when ever system boots ,even if nobody is logged or other user logged in. – Dark Knight May 05 '11 at 11:36
  • 3
    You need to redesign this as a service, IMO – Marc Gravell May 05 '11 at 11:41
  • @Marc: Ok then is it possible to display the event logs of service in an application when user logs in ? – Dark Knight May 05 '11 at 11:57
  • @Sisya, perhaps you should ask about the *real* goal of what you're trying to do, instead of just hinting at it. First of all, yes, it *is* possible to trick a winforms application to run. Will you see it? No. Will you be able to interact with it once logged in? Doubtfully. Why exactly do you need it to run before logging in? If you can tell us more about what you're trying to do you might get better answers. Or... you could play 20 questions and give us one piece at a time, but you won't get good answers. – Lasse V. Karlsen May 05 '11 at 12:07
  • @ Lasse V. Karlsen :I edited my question,Is it possible to show it in system Tray...ex: Avast or any other antivirus ? – Dark Knight May 05 '11 at 12:24
  • 1
    @Sisya, as per my answer you *must* write two separate components. See http://en.wikipedia.org/wiki/Shatter_attack for an explanation as to why (sort of)! – Rob May 05 '11 at 12:36
  • 1
    Yes, Rob is exactly write, a program that runs before log-in won't appear in the tray, but you can write a service and write a tray-application that interacts with the service. – Russ Clarke May 05 '11 at 13:04

5 Answers5

7

To have:

  • Something happen between system startup and user login
  • An icon in the notification area for users to interact with

You must break your application up into two separate components. One of these will be a WinForms/WPF application which provides the notification area icon and allows the user to interact with it. The other will be a Windows Service, or possibly a scheduled task.

Once you've done this, the windows service can focus on doing whatever needs to be done prior to logon and the notification area application can assume responsibility for showing the results, or whatever else to the end user.

To answer the question you posed in comments regarding reading data from the Event Log, yes this is possible. There are other questions on here which will give you that particular answer:

Community
  • 1
  • 1
Rob
  • 45,296
  • 24
  • 122
  • 150
  • A scheduled task if running on Vista or above would be better than a service, and you wouldn't need to modify code. That would allow running the program under the Administrator account if needed while still having a UI, but I would highly recommended to break it up so the UI runs under the User account and use WCF to communicate to the tray icon if needed. – Robert Baker May 10 '11 at 06:15
  • We broke our app up by using a single Main and scanning for an argument of "-service" if we find it the service launches. If we dont we'll launch the UI Loop – Wjdavis5 Mar 25 '15 at 12:18
4

This MS article might help but it is a bit old:

http://support.microsoft.com/kb/142905

Hopefully it'll put you on the right tracks though.

Russ Clarke
  • 17,511
  • 4
  • 41
  • 45
  • I don't think so, this method actually runs before the Shell, so after the GUI loads but before Explorer loads. It does state that your program will have to launch Explorer to allow windows to continue to operate. – Russ Clarke May 05 '11 at 13:02
3

I think, it doesn't make sense, to acquire user input before a user has logged into the system. So, if the application needs input from a user, why start it before the use has logged in? If the application just starts some background work, than you should use a windows service, as this is the prefered way in windows.

nhok
  • 108
  • 5
  • i mean my application must be running even before log in and it should sit on System Tray from which I can "show" or open Interface for user – Dark Knight May 05 '11 at 12:14
3

Type in run gpedit.msc, for Group Policy, There you can set start up script. Application will launch before Windows Login, Step to produce :-

Start --> Run --> gpedit.msc --> Local Computer Policy --> Windows Settings --> Script (Startup/ShutDown),

Add you .exe It will launch Before login. Do not try more in Group Policy, it may happen harmful for System

By Programmatic logic, Try with registry key this value is updating in registry, by our program we can update directly registry then we can call application

agf
  • 171,228
  • 44
  • 289
  • 238
2

You can schedule any application to be run when computer is powered on using Windows Task Scheduler. There is a corresponding option there. But why would you need this? You should use a service for this.

Vladimir Perevalov
  • 4,059
  • 18
  • 22