View Full Version: Adding to Startup

C++ Learning Community > C++ Help > Adding to Startup


Title: Adding to Startup


Rmstn1580 - February 4, 2007 09:54 PM (GMT)
Is there a way I could get a program to add itself to the Windows start-up list? What I'm trying to do is make a program that you insert the disk, it opens itself automatically, and adds itself to the start-up list so the next time and every time the computer is started, that program will run.

adeyblue - February 4, 2007 11:21 PM (GMT)
Like C-Man said, you can create an entry in the registry or put a shortcut to your program in the startup folder.

Adding to the registry is the simplest, just 3 lines of code using SHRegSetPath:

CODE

// include shlwapi.h and link to shlwapi.lib/libshlwapi.a

TCHAR szAppPath[MAX_PATH] = TEXT("");

GetModuleFileName(NULL, szAppPath, MAX_PATH);

SHRegSetPath(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), TEXT("Your App Name"), szAppPath, 0);


Rmstn1580 - February 4, 2007 11:34 PM (GMT)
I have another question :) Is it possible to move an executable file to a folder? Like a setup program runs then moves the main executable file to another location? I can do it with text files but I don't know how to do it with executable files.

adeyblue - February 4, 2007 11:49 PM (GMT)
And lo, MS did send from the heavens MoveFile (which also moves directories), there's also CopyFile. I don't know if they can move an application file that's already running though. You might be best off creating a stub app that runs first, copies all your files/folders/whatever to wherever, then starts your main app, or just use an installer package like NSIS or something and let that do the grunt work.

Rmstn1580 - February 5, 2007 12:20 AM (GMT)
Thank you for everything :) I have finished my project and it is working fine.




Hosted for free by InvisionFree