Results 1 to 11 of 11

Thread: [1.0/1.1] Starting up a program automatically when the computer re-boots

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    [1.0/1.1] Starting up a program automatically when the computer re-boots

    Hi. I'm creating a window application and not a service. If it was a service it would start automatically when the computer re-boots. However how do you program your window application to start automatically when the program re-boots?

    I know of one way and that is to insert the .exe file in the STARTUP menu in the program list but this is too obvious and the user could delete it by mistake. Is there any other way to enable a window application to start automatically when the computer re-boots?

    Jennifer.

    I was just researching, is there a way to set a registry key to have your program start up automatically?
    Last edited by drattansingh; Jun 7th, 2006 at 08:50 AM.

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    Anything in there should run upon windows startup. The type of value to create in there is a string (shows up as REG_SZ in the values list).

    The data is what you want to run (with command line params there too, if your program requires them).

    If you want your program to only run once (first time windows is restarted) the put your value in the RunOnce key (or possibly RunOnceEx, not sure which would be best.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    oK. I checked and found the registry key. Now I do not want to put it there manually. Is there anyway in c# I could set the directory? Either from the setup build or probably everytime the program starts, check to see if its set, and if not, then set it. Is that possible with some pseudocode or some reference?

  4. #4

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    Nobody knows? Does this mean that I cannot do this through a C sharp program?

    Jennifer

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    You can create the registry entry with your setup project and you can put code in your app to check for that registry value each time it shuts down, but there is no way for your app to check the registry after it is closed, so if the user deletes the key after your app is shut down then your app will not start with Windows. Getting and setting information from the registry is just a matter of using the Microsoft.Win32.Registry and .RegistryKey classes.
    Last edited by jmcilhinney; Jun 12th, 2006 at 07:21 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    I hope this helps
    Code:
    Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true).SetValue("MyApp",Application.ExecutablePath);
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    Thanks guys, i'll try it out and post back a reply - Jen

  8. #8

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    Hi. I tried it out and it worked. However there is a little problem. I developed a very simple application with a notify icon, when the computer booted, the application started, but not the notify icon. I checked in the processes and the program was started. I tried it again with some applications, and when the computer booted, the program started but the forms didnt display. It seems to me that apparently it is starting before some critical feature necessary to bring up the forms. Anyone knows how to solve this problem?

    Jennifer

  9. #9

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    Ok. I found the error but dont know how to solve it. When I have this program, and starts it, it starts fine, but when it starts after a reboot it fails. In my program I am reading a file: file.xml which is located:

    @"Files\file.xml"


    Now when the program starts from the auto-reboot, what is happenning is that it is not reading the path of the folder where the files exist. So that the path statement is actually:

    c:\Documents and settings\Administrator\Files\file.xml

    to which it is generating the file does not exist. Now the real path to the application folder is:

    c:\Program Files\home\test\bin\debug

    in that path, i have a folder called Files and only one file: file.xml.


    Apparently it is reading the default path as the desktop.


    Originall I had:
    Microsoft.Win32.Registry.LocalMachine....

    I changed it to:

    Microsoft.Win32.Registry.CurrentUser....

    but it is not working, the same problem. Wierd problem, why when I say:

    @\Files....

    It is assuming c:\....\Desktop\Files\file.xml

  10. #10
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    Use
    Code:
    Application.StartupPath+@"\Files\file.xml";
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  11. #11

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Starting up a program automatically when the computer re-boots

    LOL. that simple huh, Thanks!!!

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