Running aplication before windows login.

EFileTahi-A

Contributor
Joined
Aug 8, 2004
Messages
623
Location
Portugal / Barreiro
Hello guys, it has been a while...

I need to run my application in background, before anyone logs in the computer. After some research I ventured myself in creating a Windows Service to do the trick.

I've created this windows service but I simply can't make it execute my application (SQLGuardian.exe):

Code:
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            MessageBox.Show("Service Started!");
            Process.Start("D:\\SQLGuardian.exe");
        }

        protected override void OnStop()
        {
        }
    }

This service runs great, and appears in the services list, but when I start it nothing happens, except for a message saying that it opened and it closed after, as there were no work to do. The OnStart event is never called, not even when I'm debuging it, and I don't have the slightest clue why not.

Anyway, If there is a simpler way of executing an application before login, well, I'm all ears! It should work on Windows Server 2003 though.


Thanks for any help on the subject!
 
Last edited:
You cannot use a Messagebox that way in a service - a windows service runs on a different desktop to the logged on user and that is where it would display things (apart from the fact there is nobody to view them).

If you replace the messagebox call with a call to EventLog.WriteEntry instead and see if the message gets written to the log.

Does the sqlguardian.exe seem to be getting started - even if only briefly?
 
Yeah I cannot view the messagebox, that was a test to see if it would trigger the OnStart event while in debug mode.

Regarding the SQLGuardian.exe, well it does not run, when it does an icon on appears in system tray. Is this the right way of using the windows service? I mean to call an external application, the SQLGuardian.exe (which is a Windows Form) can it be called like that? Is there a KEY in the Windows 2003 registry to run applications before login?
 
It won't run on your desktop though - it will run on the service's desktop (which you can't see). If you check under taskmanager is it shown as a running process? You will probably need to show processes from all users though.

If the SQLGuardian is something you have written then it might be easier to turn that into a service and have a seperate app that sits in the notification area which communicates with the running service. If the app is from some other 3rd party then this is a way but a messy one (in fact MS have a tool in the resource kit called srvany.exe that does just this kind of thing).
 
I checked it, there was nothing on the task manager (including users)

SQLGuardian is an application I made to perform SQL backups to specific places at specific hours.

Anyway, wasn't suppose to trigger a breakpoint on the OnStart event while in dubug mode? I can successfully trigger it on InitializeComponent().
 
Are there any errors being logged in the event log? Is the code doing anything other than the few lines above? Does the account the service is running under have permissions to run the SQLGuardian application?

If this is sql server is there any reason you cannot just use it's built in scheduler to perform these backups?
 
Are there any errors being logged in the event log? Is the code doing anything other than the few lines above? Does the account the service is running under have permissions to run the SQLGuardian application?

No errors and the only code it has is the one shown on my opening post, plus it is being tested with an administrator account with full permission.

If this is sql server is there any reason you cannot just use it's built in scheduler to perform these backups?

We are using SQL Express 2008, so it does not has such option, furthermore SQL is unable to backup directly to a specific place within the network, the backup must first be placed locally. Only then it can be copied elsewhere, and this is exactly what my application is doing, backing up locally and moving the file to a specific place into a specific machine. It has the ability of pointing different databases to different places at different hours as many times we wish per day and per database.

Anyway, I will skip the windows service thing, I'm out of time. I will simply register it on the Local_Machine(...)Run. We simply need not to forget to login whenever the server reboots.

Thanks anyway Damp, it is cool to know you are still around the forum :D. You've saved me a lot of trouble in the past.

Take care!
 
I think that what you really want to do is have your SQLGuardian.exe application run as a service.

That way you will not need to be logged in, as PD said, you should write the windows service to _do_ all the work, and write a winforms application to communicate with the service and tell it what to do.
 
Back
Top