diff --git a/releasenotes/notes/fix_logging_win_installer-c750541f4fd49b77.yaml b/releasenotes/notes/fix_logging_win_installer-c750541f4fd49b77.yaml new file mode 100644 index 00000000000000..d462b6a88d38bc --- /dev/null +++ b/releasenotes/notes/fix_logging_win_installer-c750541f4fd49b77.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fix some string logging in the Windows installer. diff --git a/tools/windows/install-help/cal/FinalizeInstall.cpp b/tools/windows/install-help/cal/FinalizeInstall.cpp index 360bbc1cc96e8e..b927103f7cacc2 100644 --- a/tools/windows/install-help/cal/FinalizeInstall.cpp +++ b/tools/windows/install-help/cal/FinalizeInstall.cpp @@ -368,8 +368,8 @@ UINT doFinalizeInstall(CustomActionData &data) if (!bRet) { DWORD lastErr = GetLastError(); - std::string lastErrStr = GetErrorMessageStr(lastErr); - WcaLog(LOGMSG_STANDARD, "CreateSymbolicLink: %s (%d)", lastErrStr.c_str(), lastErr); + auto lastErrStr = GetErrorMessageStrW(lastErr); + WcaLog(LOGMSG_STANDARD, "CreateSymbolicLink: %S (%d)", lastErrStr.c_str(), lastErr); } else { diff --git a/tools/windows/install-help/cal/TargetMachine.cpp b/tools/windows/install-help/cal/TargetMachine.cpp index ec684695b931da..e62bdfbf8d2b7c 100644 --- a/tools/windows/install-help/cal/TargetMachine.cpp +++ b/tools/windows/install-help/cal/TargetMachine.cpp @@ -214,7 +214,7 @@ DWORD TargetMachine::DetectDomainInformation() return nErr; } _dcFlags = dcInfo->Flags; - WcaLog(LOGMSG_STANDARD, "Domain Controller is %s", IsReadOnlyDomainController() ? "Read-Only" : "Writable"); + WcaLog(LOGMSG_STANDARD, "Domain Controller is %S", IsReadOnlyDomainController() ? L"Read-Only" : L"Writable"); NetApiBufferFree(dcInfo); } } diff --git a/tools/windows/install-help/cal/customaction.h b/tools/windows/install-help/cal/customaction.h index 5da76ba3f8b270..8d9b9a6057d4e7 100644 --- a/tools/windows/install-help/cal/customaction.h +++ b/tools/windows/install-help/cal/customaction.h @@ -118,17 +118,19 @@ UINT doUninstallAs(UNINSTALL_TYPE t); // see https://stackoverflow.com/a/45565001/425565 // Template ErrType can be HRESULT (long) or DWORD (unsigned long) -template std::string GetErrorMessageStr(ErrType errCode) +template std::wstring GetErrorMessageStrW(ErrType errCode) { const int buffsize = 4096; - char buffer[buffsize]; + wchar_t buffer[buffsize]; const DWORD len = - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, nullptr, // (not used with FORMAT_MESSAGE_FROM_SYSTEM) errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &buffer[0], buffsize, nullptr); if (len > 0) { - return std::string(buffer, len); + return std::wstring(buffer, len); } - return "Failed to retrieve error message string."; + std::wstringstream wsstr; + wsstr << L"Failed to retrieve error message string for code " << errCode; + return wsstr.str(); } diff --git a/tools/windows/install-help/cal/stopservices.cpp b/tools/windows/install-help/cal/stopservices.cpp index bdb14fe371e558..0527ee6ede5b7c 100644 --- a/tools/windows/install-help/cal/stopservices.cpp +++ b/tools/windows/install-help/cal/stopservices.cpp @@ -881,8 +881,8 @@ int uninstallServices(CustomActionData &data) DWORD rbret = services[i].destroy(hScManager); if (rbret != 0) { - std::string lastErrStr = GetErrorMessageStr(rbret); - WcaLog(LOGMSG_STANDARD, "Failed to uninstall service %s (%d)", lastErrStr.c_str(), rbret); + auto lastErrStr = GetErrorMessageStrW(rbret); + WcaLog(LOGMSG_STANDARD, "Failed to uninstall service %S (%d)", lastErrStr.c_str(), rbret); } } WcaLog(LOGMSG_STANDARD, "done uinstalling services"); diff --git a/tools/windows/install-help/cal/userrights.cpp b/tools/windows/install-help/cal/userrights.cpp index 63524af4015767..2fcc3823521ffd 100644 --- a/tools/windows/install-help/cal/userrights.cpp +++ b/tools/windows/install-help/cal/userrights.cpp @@ -321,14 +321,12 @@ DWORD AddUserToGroup(PSID userSid, wchar_t *groupSidString, wchar_t *defaultGrou memset(&lmi0, 0, sizeof(LOCALGROUP_MEMBERS_INFO_0)); lmi0.lgrmi0_sid = userSid; - std::string asciiname; - getGroupNameFromSidString(groupSidString, defaultGroupName, groupname); WcaLog(LOGMSG_STANDARD, "Attempting to add to group %S", groupname.c_str()); nErr = NetLocalGroupAddMembers(NULL, groupname.c_str(), 0, (LPBYTE)&lmi0, 1); if (nErr == NERR_Success) { - WcaLog(LOGMSG_STANDARD, "Added ddagentuser to %s", asciiname.c_str()); + WcaLog(LOGMSG_STANDARD, "Added user to %S", groupname.c_str()); } else if (nErr == ERROR_MEMBER_IN_GROUP || nErr == ERROR_MEMBER_IN_ALIAS) { @@ -352,7 +350,7 @@ DWORD DelUserFromGroup(PSID userSid, wchar_t *groupSidString, wchar_t *defaultGr lmi0.lgrmi0_sid = userSid; getGroupNameFromSidString(groupSidString, defaultGroupName, groupname); - WcaLog(LOGMSG_STANDARD, "Attempting to remove from group %s", groupname.c_str()); + WcaLog(LOGMSG_STANDARD, "Attempting to remove from group %S", groupname.c_str()); nErr = NetLocalGroupDelMembers(NULL, L"Performance Monitor Users", 0, (LPBYTE)&lmi0, 1); if (nErr == NERR_Success) {