I have a Window (win32 API) Application in visual c++. I am not using MFC. I have to run my application on windows start up. I am using windows 7 and visual studio 2008. Can any one help me out in achieving the above task? Thanks in advance.
views:
259answers:
5Don't know about Win32 but how about a simple shortcut to your program:
C:\Documents and Settings\\Start Menu\Programs\Startup
(or use All Users instead of USER)
Just add it to the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key int he registry.
The most straightforward way is to create a registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
(Insert the code into your installation program to add the key.)
If you create it under HKEY_LOCAL_MACHINE, it will apply to all users of the machine. If you create it under HKEY_CURRENT_USER, then the program will run automatically upon startup only for that user.
Look at autoruns by SysInternals (now Microsoft). It will show you the many ways a process can be started by Windows. You will want to check out the Logon tab which shows several file and registry settings that can enable you to start stuff on Logon. Services and Drivers start on system startup (don't require a logon). Bootexecute allows you to run stuff at boot time which is probably not what you want.
The rest of the tabs show you how to hook into various other system processes to load your code. It's no wonder Windows is ripe for malware authors especially if you run as root.
If you create the registry entry under HKEY_LOCAL_MACHINE, the application startup is forced on all users on the local machine. Write entries below HKEY_CURRENT_USER key to target only the current logged(active) user while this application is launched.