-
Mar 24th, 2015, 05:53 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] My app needs to start automatically on a server....
Hi all.
I made an application for a customer that needs to run on a server. Initially, a shortcut to the application placed in the StartUp folder of the Windows Start button was just fine, but now it's not good enough anymore, as the server might not have any user login after bootup (which was pretty obvious from the beggining, but hey, I have mentioned many times I do make dumbass mistakes...).
So. Is it possible to have my app start-up automatically on the server without turning it into a service (which has other impacts on the client side of things...)?
Thanks in advance!
Don't ask why, just reboot!
-
Mar 24th, 2015, 06:29 PM
#2
Re: My app needs to start automatically on a server....
Here is the solution you want. I used it many many years ago when I faced the same problem.
-
Mar 24th, 2015, 06:32 PM
#3
Re: My app needs to start automatically on a server....
Here is a page that describes the same thing with more detail in case the MSDN page isn't clear enough on what you need to do.
-
Mar 24th, 2015, 06:37 PM
#4
Re: My app needs to start automatically on a server....
I just followed Niya's link and, while it might be relevant, it's not the first thing that would have come to my mind. Firstly, there are actually two Startup folders, the combined contents of which were displayed on the old Start Menu. One is for the current user and one is for all users. To be honest, I'm not sure whether the items in the folder for all users are executed only when an interactive user logs in or when the machine starts up. That would be easy enough to test though.
Apart from that, there are also two Registry keys that correspond to startup items. One is under HKEY_CURRENT_USER while the other is under HKEY_LOCAL_MACHINE so, again, one for the current user and one for all users. The path of each under their hive is "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run".
-
Mar 24th, 2015, 06:51 PM
#5
Re: My app needs to start automatically on a server....
Originally Posted by jmcilhinney
I just followed Niya's link and, while it might be relevant, it's not the first thing that would have come to my mind. Firstly, there are actually two Startup folders, the combined contents of which were displayed on the old Start Menu. One is for the current user and one is for all users. To be honest, I'm not sure whether the items in the folder for all users are executed only when an interactive user logs in or when the machine starts up. That would be easy enough to test though.
Apart from that, there are also two Registry keys that correspond to startup items. One is under HKEY_CURRENT_USER while the other is under HKEY_LOCAL_MACHINE so, again, one for the current user and one for all users. The path of each under their hive is "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run".
The StartUp folders only start applications when a user logs in. Only services can be started in session 0 which is the only active session before any user logs in.
-
Mar 24th, 2015, 07:24 PM
#6
Re: My app needs to start automatically on a server....
Originally Posted by Niya
The StartUp folders only start applications when a user logs in. Only services can be started in session 0 which is the only active session before any user logs in.
Is that true for the Run keys in the Registry as well? I'd not really thought of that but I suppose it would make sense. I also suppose that I could test it for myself.
-
Mar 24th, 2015, 07:58 PM
#7
Re: My app needs to start automatically on a server....
It is true for Run keys too. When Windows boots, only one session is active which is session 0. Session 0 is made especially for Windows Services. Running services is very different from running normal applications. Normal applications cannot be plainly executed within session 0. The Run key and StartUp folders are made to run typical applications, not services. However, there is nothing that prevents a normal application from running in Session 0 so you can use a service to shell out and execute a normal application. That is what the links I posted show you how to do.
-
Mar 24th, 2015, 10:20 PM
#8
Thread Starter
Fanatic Member
Re: My app needs to start automatically on a server....
Hi guys,
I just came back home after a night out and notice the replies to my thread. Thanks a lot for your help. I will check it out in the morning and get back to you with either a success story or questions.
Cheers,
Don't ask why, just reboot!
-
Mar 25th, 2015, 01:52 PM
#9
Re: My app needs to start automatically on a server....
autostart and registry run will not help here, but
i think you can schedule your application as planned task on the server and set the start to 'when computer boots' or something like that. i had tested that once and found that the program gets started around when the login screen appears i.e. before someone logs on.
you might want to give it a try.
-
Mar 25th, 2015, 02:00 PM
#10
Re: My app needs to start automatically on a server....
Here's a crazy thought, re-build the app as a Windows Service project... There isn't going to be any form to display so it shouldn't be too difficult. Then simply install it as a service, and set the settings to autostart, just like any other service.
-tg
-
Mar 25th, 2015, 02:38 PM
#11
Re: My app needs to start automatically on a server....
Originally Posted by digitalShaman
autostart and registry run will not help here, but
i think you can schedule your application as planned task on the server and set the start to 'when computer boots' or something like that. i had tested that once and found that the program gets started around when the login screen appears i.e. before someone logs on.
you might want to give it a try.
Yea, the task scheduler can run applications across sessions but I'm unsure if it will run an app in session 0.
-
Mar 25th, 2015, 03:07 PM
#12
Thread Starter
Fanatic Member
Re: My app needs to start automatically on a server....
Hi guys, I'm back.
Niya, thanks a lot for the links. They are quite what I was looking for. The only thing is that it complicates the install process on the server, which my customer may dislike. I'll submit it to him and see where it leads me.
Tg, I've considered that but rebuilding the app is a big change, specially at this stage of the project (application is installed and customer is testing). My app is the same both on the server and client computers, although no UI appears on the server. If I change the app to a service, than I need to keep two versions of the same code (which is out of the question), or to merge shared code in a DLL (which is a huge risk of generating new problems). So if I could go back in time, I would most certainly have two exe files (service and application) that share a DLL, but I've been looking for that reference all day in my VS and can't find it! ('Imports System.TimeTravel')...
Again, thanks a lot for your help!
Last edited by Alain; Mar 25th, 2015 at 03:33 PM.
Don't ask why, just reboot!
-
Mar 25th, 2015, 03:20 PM
#13
Re: My app needs to start automatically on a server....
Originally Posted by Alain
Hi guys, I'm back.
Niya, thanks a lot for the links. They are quite what I was looking for. The only thing is that it complicates the install process on the server, which my customer may dislike. I'll submit it to him and see where it leads me.
Tg, I've considered that but rebuilding the app is a big change, specially at this stage of the project (application is installed and customer is testing). My app is the same both on the server and client computers, although no UI appears on the server. If I change the app to a service, than I need to keep two versions of the same code (which is out of the question), or to merge shared code in a DLL (which is a huge risk of generating new problems). So if I could go back in time, I would most certainly have two exe files (service and application) that share a DLL, but I've been looking for that reference all day in my VS and can't find it! ('Imports System.TimeTavel')...
Again, thanks a lot for your help!
haven't you tried the scheduled task? as i said: i tried it several years ago and it worked well. i dont know your customer but a server admin should be able to set up a scheduled task as simple as that. and the impact to your application should be equal to zero.
-
Mar 25th, 2015, 03:25 PM
#14
Re: My app needs to start automatically on a server....
Originally Posted by Niya
Yea, the task scheduler can run applications across sessions but I'm unsure if it will run an app in session 0.
yes it will. or i will be really surprised. actually it is quite normal to have a scheduled task run some executable under some user account even though none is logged on. we use that alot however these are 'one time run at xy' not 'run upon startup'. but what difference should it make?
-
Mar 25th, 2015, 03:26 PM
#15
Thread Starter
Fanatic Member
Re: My app needs to start automatically on a server....
I'm sorry DS, it seems I skipped over your post when reading through them! Yes, I will try that for sure. Zero impact is good! Me like zero impact...
Don't ask why, just reboot!
-
Mar 26th, 2015, 11:56 AM
#16
Thread Starter
Fanatic Member
Re: My app needs to start automatically on a server....
Well, it looks like I'm going to go with the scheduled task route. Only thing though, it's the first time I schedule a task and I can't seem to do it right! Right now I'm at the point where the task is all set-up and ready to be executed at computer boot-up (wihout any user needing to log in), but it doesn't work just yet. If I list all tasks, mine is shown and is appearently 'ready', but it's not executed at computer startup. If I right-click on it, and start it manually, then it starts my app with no problem. But I haven't (yet) figured out why it won't get started automatically when the computer has just booted.
I'll keep searching in the interwebs for some answers, but if any of you guys has an idea, you're welcome to share it with me...
Thanks!
Don't ask why, just reboot!
-
Mar 26th, 2015, 12:43 PM
#17
Thread Starter
Fanatic Member
Re: My app needs to start automatically on a server....
Oh well. I figured out why my task wasn't starting... It actually did, but my app crashed because the code is triggered when the main form shows. Which it doesn't because the user has not logged in yet, so no UI can be called.
Damn.
I'll have to think of something else.
Don't ask why, just reboot!
-
Mar 26th, 2015, 02:33 PM
#18
Thread Starter
Fanatic Member
Re: My app needs to start automatically on a server....
Ok, final update. IT WORKS!!!
The initial error I was having had nothing to do with my app using forms at all. That doesn't seem to be an issue at all. I just badly set up the scheduled task, that's all.
So thanks for your help everyone!
Cheers,
Don't ask why, just reboot!
-
Mar 26th, 2015, 05:26 PM
#19
Re: My app needs to start automatically on a server....
Originally Posted by Alain
Tg, I've considered that but rebuilding the app is a big change, specially at this stage of the project (application is installed and customer is testing). My app is the same both on the server and client computers, although no UI appears on the server. If I change the app to a service, than I need to keep two versions of the same code (which is out of the question), or to merge shared code in a DLL (which is a huge risk of generating new problems).
Changing an app from a service is actually not that difficult. You simply have to change the way the app starts. I have an app somewhere around on my HD that can run a both a service and a normal application. I read to command line to determine how it should be started.
-
Mar 26th, 2015, 08:15 PM
#20
Thread Starter
Fanatic Member
Re: [RESOLVED] My app needs to start automatically on a server....
Thanks for the info Niya. But for now I largly prefer the option that implies no code change at all. As I said, the app is being tested right now.
But I'll keep that in mind if I ever stumble upon a similar situation.
Cheers,
Don't ask why, just reboot!
-
Mar 27th, 2015, 07:53 AM
#21
Re: [RESOLVED] My app needs to start automatically on a server....
glad this worked out for you. you need to consider some things though: if your app crashes it will not be restarted until server reboot. if your app leaks it will cause issues on the server. if you did not set all the scheduled tasks properties carefully the server may kill the task after a while. any messagebox of your app or other required user interaction wil, of course not work.
you may want to consider scheduling the task in a way so that your app is periodically restarted e.g. once every night, whatever is appropriate for you.
-
Mar 27th, 2015, 08:16 AM
#22
Thread Starter
Fanatic Member
Re: [RESOLVED] My app needs to start automatically on a server....
Thanks for the heads up DS, but those potential issues you describe have already been dealth with from the start. The admin client session periodically checks on the server status, and warns him if the server app is not running. Also, any messages the server needs to display actually shows up on the admin's computer. Lastly, if the server is down for a while and the admin doesn't notice it (let's say he's on vacation), then nothing bad really happens, just users request remain in a 'pending state' until the admin (and the server) are back at work.
I don't think the app leaks memory, but that is planed to be monitored once my the app will be up and running for a while.
Thanks for the warning nonetheless!
Don't ask why, just reboot!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|