65.9K
CodeProject is changing. Read more.
Home

Adding your application to the Windows Startup

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.41/5 (11 votes)

Jul 11, 2001

viewsIcon

92336

downloadIcon

3010

An article on including an application in the Windows startup list

Introduction

Sometimes you want to make you application run everytime Windows starts up. One approach is to develop a service, but it will work just in NT or 2K boxes. To make it happen in Win95/98 boxes is necessary to change the registry settings.

The registry key is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run to all users and HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run to the current user.

To make this task easier I wrote a wrapper class (CWinStartup) that adds and removes applications from the startup

bool AddApp(HINSTANCE hInst, LPCTSTR lpszName, StartupUser user) Add an app to the startup through the HINSTANCE
bool AddApp(LPCTSTR lpszName, LPCTSTR lpszPath, StartupUser user) Add the app according to the path defined
bool RemoveApp(LPCTSTR lpszName, StartupUser user) Removes the app from the registry

All the methods are static. This class has been tested on Win2K boxes only, but as far as I'm concerned it works in all Windows versions.