Run on Startup ?

This is a discussion on Run on Startup ? within the Windows Programming forums, part of the Platform Specific Boards category; I'm currently writing a program that will monitor the clipboard constantly, and on detecting a certain text string, will run ...

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.

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.

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.

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.

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?

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 ?