(Transferred from: http://blog.csdn.net/weiren2006/article/details/7443362)
Let the software run automatically at system startup, by modifying the registry implementation.
Add the program path you want to start in \hkey_local_machine\software\microsoft\windows\currentversion\run, with the following code:
voidAutoStart (boolflag)
{
Write to the registry, boot from boot
HKEYHKEY;
Find the system's Startup items
lpctstrlprun= (wchar_t*)QString("software\\microsoft\\windows\\currentversion\\ Run "). UTF16 ();
Open Startup Item Key
longLret=regopenkeyex (Hkey_local_machine,lprun,0, Key_write,&hkey);
if (lret==error_success)
{
DWORDdwret=qapplication:: Applicationfilepath (). Length () *2;
Add a child key and set a value
if (flag==true)
{
Lret=regsetvalueex (HKey, (WCHAR*)QString("test"). UTF16 (),0, REG_SZ,
(BYTE*) qapplication:: Applicationfilepath (). UTF16 (), dwret);
}
Else
{
Lret=regsetvalueex (HKey, (WCHAR*)QString("test"). UTF16 (),0, REG_SZ,
(BYTE*) "", Dwret);
}
Close the registration table
RegCloseKey (HKey);
if (lret!=error_success)
{
Qdebug ("error");
}
}
}