From 516608340616cf081cf96fedaffee4600613f352 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sun, 14 Apr 2024 21:03:51 +0800 Subject: [PATCH] Fix. Msi, reg add SoftwareSASGeneration (#7708) Signed-off-by: fufesou --- res/msi/CustomActions/CustomActions.cpp | 52 ++++++++++++++++++++- res/msi/CustomActions/CustomActions.def | 1 + res/msi/Package/Components/RustDesk.wxs | 2 + res/msi/Package/Fragments/CustomActions.wxs | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/res/msi/CustomActions/CustomActions.cpp b/res/msi/CustomActions/CustomActions.cpp index 7f7f24eee..37a728a4b 100644 --- a/res/msi/CustomActions/CustomActions.cpp +++ b/res/msi/CustomActions/CustomActions.cpp @@ -287,7 +287,7 @@ UINT __stdcall AddFirewallRules( LPWSTR pwzData = NULL; size_t szNameLen = 0; - hr = WcaInitialize(hInstall, "AddFirewallExceptions"); + hr = WcaInitialize(hInstall, "AddFirewallRules"); ExitOnFailure(hr, "Failed to initialize"); hr = WcaGetProperty(L"CustomActionData", &pwzData); @@ -541,3 +541,53 @@ LExit: er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); } + +UINT __stdcall AddRegSoftwareSASGeneration(__in MSIHANDLE hInstall) +{ + HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; + + LSTATUS result = 0; + HKEY hKey; + LPCWSTR subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; + LPCWSTR valueName = L"SoftwareSASGeneration"; + DWORD valueType = REG_DWORD; + DWORD valueData = 1; + DWORD valueDataSize = sizeof(DWORD); + + HINSTANCE hi = 0; + + hr = WcaInitialize(hInstall, "AddRegSoftwareSASGeneration"); + ExitOnFailure(hr, "Failed to initialize"); + + hi = ShellExecuteW(NULL, L"open", L"reg", L" add HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /f /v SoftwareSASGeneration /t REG_DWORD /d 1", NULL, SW_HIDE); + // https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew + if ((int)hi <= 32) { + WcaLog(LOGMSG_STANDARD, "Failed to add registry name \"%ls\", %d, %d", valueName, (int)hi, GetLastError()); + } + else { + WcaLog(LOGMSG_STANDARD, "Registry name \"%ls\" is added", valueName); + } + + // Why RegSetValueExW always return 998? + // + result = RegCreateKeyExW(HKEY_LOCAL_MACHINE, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); + if (result != ERROR_SUCCESS) { + WcaLog(LOGMSG_STANDARD, "Failed to create or open registry key: %d", result); + goto LExit; + } + + result = RegSetValueExW(hKey, valueName, 0, valueType, reinterpret_cast(valueData), valueDataSize); + if (result != ERROR_SUCCESS) { + WcaLog(LOGMSG_STANDARD, "Failed to set registry value: %d", result); + RegCloseKey(hKey); + goto LExit; + } + + WcaLog(LOGMSG_STANDARD, "Registry value has been successfully set."); + RegCloseKey(hKey); + +LExit: + er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; + return WcaFinalize(er); +} diff --git a/res/msi/CustomActions/CustomActions.def b/res/msi/CustomActions/CustomActions.def index a089c583e..a73ecda26 100644 --- a/res/msi/CustomActions/CustomActions.def +++ b/res/msi/CustomActions/CustomActions.def @@ -10,3 +10,4 @@ EXPORTS CreateStartService TryDeleteStartupShortcut SetPropertyFromConfig + AddRegSoftwareSASGeneration diff --git a/res/msi/Package/Components/RustDesk.wxs b/res/msi/Package/Components/RustDesk.wxs index a44d8bb73..df9463fe8 100644 --- a/res/msi/Package/Components/RustDesk.wxs +++ b/res/msi/Package/Components/RustDesk.wxs @@ -58,6 +58,8 @@ + + diff --git a/res/msi/Package/Fragments/CustomActions.wxs b/res/msi/Package/Fragments/CustomActions.wxs index 0454a6731..e064b188e 100644 --- a/res/msi/Package/Fragments/CustomActions.wxs +++ b/res/msi/Package/Fragments/CustomActions.wxs @@ -15,5 +15,6 @@ +