Thread: Run on Startup ?

  1. #1
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209

    Run on Startup ?

    I'm currently writing a program that will monitor the clipboard constantly, and on detecting a certain text string, will run a function. I need this program to run on startup, in the background, but I'm not sure how to do this. I can do it through the registry, but I'm not sure how to add a key to the registry without having to run a .reg file, and also, the registry changes according to OS ( 95, 98, 2k, Me, NT, XP ). Can anyone give me advice ?
    Thank you.

  2. #2
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    Simple: make the program write an lnk (shortcut) file in the C:\windows\start menu\programs\starup folder, that will make your program run on start-up quite easily. Open a lnk file in notepad (or another text editor, a hexeditor would be best), you'll notice that they are really quite simple, although bats are superior.

  3. #3
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Thank you for your help, however this leads to a question :

    Writing to C:\Windows, I believe some of the Windows OSs don't have the Windows directory, but Winnt instead, such as XP ( Pro, at least ). Also, to place something in the Startup folder, you need to go through a username, such as :
    C:\Documents and Settings\User\Start Menu\Programs\Startup
    and this may cause problems, finding the username, or running it on DefaultUser or AllUsers, and then having the program run on each user's log, instead of one log.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Another solution is window services.

    Kuphryn

  5. #5
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Thanks for your help. I CAN use the registry, however I'm having problems with that. If anyone has a very simple code where they open the registry and put a key in, and could show it to me, I'd be very grateful.
    Thank you.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    The registry functions can seem difficult when first learning them, but the're just as easy to call as CreateFile() and CreateProcess()

    Here's an example that will give you most everything you need.
    Once you understand that code, all you have to look up is RegSetValueEx() for adding a key to the registry (for starting your program).

    If you're still at a dead end, then post the registry writting code you've written so far and we'll get you back on track.

    gg

  7. #7
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    I was wondering if there is a book that goes into registries/DLLs/multithreading in more depth than Petzold's book, which covers DLLs an Multithreading just barely, and doesnt cover the registry at all?

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    This book may be what you're looking for - just looking at the table of contents.

    gg

  9. #9
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    This book may be what you're looking for - just looking at the table of contents.
    bingo. Exactly what I was looking for, thanks codeplug

  10. #10
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Thanks for your help, I can now write my keys and values to the registry. However, it leads to yet another problem :

    Using GlobalAlloc, I allocate and reserve memory to use during my program. However, my program will run from startup, until the computer is shut down, meaning the memory is never restored. Thus :
    1. Does this cause a problem ?
    2. How can I make it so that when the program receives the order to close, it calls GlobalFree ?

    My program is running a recurring for loop ( for(; ) and so isn't supposed to break at all. I tested using GlobalAlloc without GlobalFree, which creates an error when the program closes. How can I get around this ?

    Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to run an exe command in c++ and get back the results?
    By mitilkhatoon in forum C++ Programming
    Replies: 5
    Last Post: 09-21-2006, 06:00 PM
  2. calculating the mode
    By bigggame in forum C Programming
    Replies: 10
    Last Post: 06-13-2006, 03:04 AM
  3. How I can Run exe file in C++
    By palang in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2006, 11:55 AM
  4. MSVC: run w/o debugger vs run w/ debuger
    By skorman00 in forum C++ Programming
    Replies: 2
    Last Post: 01-24-2006, 09:49 PM
  5. Replies: 2
    Last Post: 10-29-2002, 04:56 PM