Fix auto-start settings on Windows

This commit is contained in:
Jonathan White 2020-06-17 17:58:24 -04:00
parent 9c0fa376a1
commit 05a0df799e
2 changed files with 3 additions and 3 deletions

View File

@ -51,7 +51,7 @@
<RegistryValue Id="Autostart.rst" Root="HKCU" Action="write"
Key="Software\Microsoft\Windows\CurrentVersion\Run"
Name="$(var.CPACK_PACKAGE_NAME)"
Value="[#CM_FP_KeePassXC.exe]"
Value="&quot;[#CM_FP_KeePassXC.exe]&quot;"
Type="string" />
<Condition>AUTOSTARTPROGRAM</Condition>
</Component>

View File

@ -18,6 +18,7 @@
#include "WinUtils.h"
#include <QAbstractNativeEventFilter>
#include <QApplication>
#include <QDir>
#include <QSettings>
#include <windows.h>
@ -88,14 +89,13 @@ bool WinUtils::isLaunchAtStartupEnabled() const
{
return QSettings(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat)
.contains(qAppName());
;
}
void WinUtils::setLaunchAtStartup(bool enable)
{
QSettings reg(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat);
if (enable) {
reg.setValue(qAppName(), QApplication::applicationFilePath());
reg.setValue(qAppName(), QString("\"%1\"").arg(QDir::toNativeSeparators(QApplication::applicationFilePath())));
} else {
reg.remove(qAppName());
}