Run At Startup Programmatically | CodeGuru

Run At Startup Programmatically

Environment: VC6, Win9x You can use this code to let your program run automatically at system startup, it shows you also how to use some of API registry functions. Before you start you must know that Windows knows what to run at startup by keeping a list of program’s name and pathes under the following […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 31, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: VC6, Win9x

You can use this code to let your program run automatically at system startup, it shows you also how to use some of API registry functions. Before you start you must know that Windows knows what to run at startup by keeping a list of program’s name and pathes under the following Key in the system registry:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run.

All that you will do now is to add our program’s path and name in this key by using “RegOpenKeyEx” and “RegSetValue” API registry functions. The algorithm is so simple:

FIRST : Open the “Run” key.

SECOND: Set it with new value (program’s path and name.)

Here is the source code:

LONG lnRes = RegOpenKeyEx(
           HKEY_LOCAL_MACHINE,  // handle of open key
             // The following is the address of name of subkey to open
           “SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run”,
           0L,KEY_WRITE,
           &hKey            // address of handle of open key 
       );
// now add program path to the RUN key
lstrcpy( (char *) szFilePath , LPCTSTR(m_strFileName) );
GetDlgItemText( IDC_KEYNAME, sKeyName );     //Get value name
if( ERROR_SUCCESS == lnRes )
{
   lnRes = RegSetValueEx(hKey,
                         LPCTSTR( sKeyName ),  // handle of the opened
                                               // key to set value for 
                         0,
                         REG_SZ,
                         szFilePath,   //value data
                         REG_SZ );
}

Downloads

Download demo project – 106 Kb

Download source – 14 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.