1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <windows.h>
void run_app_on_windows_startup( void )
{
HKEY hkey;
std::string key_name( "le_nom_de_ta_clé_qui_n'a_pas_d'importance" );
std::string app_path( "le\\chemin\\absolu\\de\\ton\\app\\avec\\des\\doubles\\backslashs" );
/** Open Run Registry location */
LONG ret = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
0L,
KEY_WRITE | KEY_WOW64_64KEY,
&hkey );
if ( ret == ERROR_SUCCESS )
{
/* Set full application path with a keyname to registry */
ret = RegSetValueEx( hkey,
key_name.c_str(),
0,
REG_SZ,
reinterpret_cast< const BYTE* >( app_path.c_str() ),
REG_SZ );
if( ret == ERROR_SUCCESS )
std::cout << "Set at startup has done successfully" << std::endl;
else
std::cerr << "Failed to set at startup" << std::endl;
}
else
{
std::cerr << "Failed to set at startup" << std::endl;
}
} |
Partager