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 36 37 38 39
| //démarage avec windows
void addToStartup(const char *path = "C:/Users/Nicolas/Desktop/SmartDef/bin/Release/SmartDef.exe", const char *name = "SmartDef.exe", bool state = true)
{
HKEY key;
if(state)
{
MessageBox(NULL, "lancement addtostartup", "SmartDef", MB_ICONINFORMATION);
if( RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &key)!= ERROR_SUCCESS )
{
MessageBox(NULL, "impossible d'ouvrir la clef run", "SmartDef", MB_ICONINFORMATION);
}
else
{
if( RegSetValueEx(key, name, 0, REG_SZ, (BYTE*)path, strlen(path)+1) != ERROR_SUCCESS )
{
MessageBox(NULL, "impossible de définir une nouvelle valeur", "SmartDef", MB_ICONINFORMATION);
}
else
{
RegCloseKey(key);
}
}
}
else
{
RegCloseKey(key);
MessageBox(NULL, "echec addtostartup", "SmartDef", MB_ICONINFORMATION);
}
return;
} |
Partager