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.
7 Answers
Here's some example code:
HKEY hkey = NULL;
RegCreateKey(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", &hkey);
RegSetValueEx(hkey, L"myapp", 0, REG_SZ , (BYTE*)path, (wcslen(path)+1)*2);
1 Comment
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.
Comments
Just add it to the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key int he registry.
1 Comment
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.