First, write to the registry requires administrator privileges
When build and run the program needs to write to the registry 1. Development, the project should be opened with administrator privileges;
2. Click the procedures required write to the registry, it should open the program with administrator privileges.
Second, the realization
void MoreSetWindow::sltCheckBoxStartStateChanged(bool checked) //启动
{
{
QSettings reg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
if (checked)
{
{
QString appName = QCoreApplication :: applicationName () ; // name of the program
QString appPath = QCoreApplication::applicationFilePath(); //程序路径
appPath = appPath.replace("/", "\\");
appPath = appPath.replace("/", "\\");
reg.setValue(appName, appPath);
}
else
{
reg.setValue("DeviceClient", "");
}
else
{
reg.setValue("DeviceClient", "");
}
}