2

Im trying to get my application to start one the user logs on to his or hers account.

My current code:

#ifdef Q_OS_WIN
QSettings bootUpSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
QString base_dir = qApp->applicationDirPath() + "\\MyApp.exe";

if (autoStartChecked == "true") {
    bootUpSettings.setValue("MyApp","\""+base_dir+"\"");
} else {
    bootUpSettings.remove("MyApp");
}
#endif

When I look in regedit I can see that my application has added the key with value, but for some reason the application wont auto start when i logon to Windows.

Any ideas?

user3490755
  • 955
  • 2
  • 15
  • 33

1 Answers1

3

You have to put the path to your application executable into the

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

key instead. I.e.:

QSettings bootUpSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
QString app_path = QCoreApplication::applicationFilePath();
if (autoStartChecked == "true") {
    bootUpSettings.setValue("MyApp", app_path);
} else {
    bootUpSettings.remove("MyApp");
}
vahancho
  • 20,808
  • 3
  • 47
  • 55