0
votes

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");
1
Note that a better solution is to add a shortcut to your application in the Start Menu's "Startup" folder. That can be done for either a specific user or for all users. Leave the registry alone.Cody Gray
Is it the exact code that you are running? Could you provide your working code for HKCU too to compare?John_West
@John_West I've only replaced HKEY_CURRENT_USER to HKEY_LOCAL_MACHINE, and new key is not showing.km2442
@CodyGray How does one switch between current user and all users? I've read of some AllUsers-setting supporting true and false, but can't find anything in the docs on how to use it. stackoverflow.com/questions/59510656/…Thorsten Schöning

1 Answers

3
votes

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.