简体   繁体   中英

Qt how to write to HKLM

In my Qt5.5 app I'm trying to write to

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run

registry key, to enable autorun on every account, using QSettings, but I can't do it even with Administrator Priviliges. Could you tell me how should I do it right way? If I try to use this code with HKCU to enable autorun to current user, it's working.

QSettings bootUp("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
bootUp.setValue("/MyApp", "\"" + QDir::currentPath() + "/MyApp.exe\"" + " -a -u");

What's confusing you is that you have a 32 bit process running on 64 bit Windows and you are writing to a part of the registry that is redirected by the registry redirector . So

HKLM\Software

is redirected to

HKLM\Software\Wow6432Node

You'll find your entries under there. This is nothing to worry about. The system will reads keys from both 32 and 64 views on startup.

Remember that if your code was failing to write to the registry then it would be throwing an exception.

In short, your code works, you are just looking in the wrong place in the Registry Editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM