Results 1 to 22 of 22

Thread: [RESOLVED] My app needs to start automatically on a server....

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    Resolved [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!

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    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".

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: My app needs to start automatically on a server....

    Quote Originally Posted by jmcilhinney View Post
    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: My app needs to start automatically on a server....

    Quote Originally Posted by Niya View Post
    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.

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    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!

  9. #9
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    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.

  10. #10
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: My app needs to start automatically on a server....

    Quote Originally Posted by digitalShaman View Post
    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    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!

  13. #13
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: My app needs to start automatically on a server....

    Quote Originally Posted by Alain View Post
    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.

  14. #14
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: My app needs to start automatically on a server....

    Quote Originally Posted by Niya View Post
    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?

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    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!

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    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!

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    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!

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    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!

  19. #19
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: My app needs to start automatically on a server....

    Quote Originally Posted by Alain View Post
    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    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!

  21. #21
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    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.

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    527

    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
  •  



Click Here to Expand Forum to Full Width