diff --git a/tools/msvs/msi/custom_actions.cc b/tools/msvs/msi/custom_actions.cc index 8a8417ea0b2929..32811dcb19469d 100644 --- a/tools/msvs/msi/custom_actions.cc +++ b/tools/msvs/msi/custom_actions.cc @@ -3,6 +3,8 @@ #include #include #include +#include +#include #define GUID_BUFFER_SIZE 39 // {8-4-4-4-12}\0 @@ -96,6 +98,35 @@ extern "C" UINT WINAPI BroadcastEnvironmentUpdate(MSIHANDLE hInstall) { return WcaFinalize(er); } +#define AUTHENTICATED_USERS_SID L"S-1-5-11" + +extern "C" UINT WINAPI GetLocalizedUserNames(MSIHANDLE hInstall) { + HRESULT hr = S_OK; + UINT er = ERROR_SUCCESS; + TCHAR userName[UNLEN + 1] = {0}; + DWORD userNameSize = UNLEN + 1; + TCHAR domain[DNLEN + 1] = {0}; + DWORD domainSize = DNLEN + 1; + PSID sid; + SID_NAME_USE nameUse; + + hr = WcaInitialize(hInstall, "GetLocalizedUserNames"); + ExitOnFailure(hr, "Failed to initialize"); + + er = ConvertStringSidToSidW(AUTHENTICATED_USERS_SID, &sid); + ExitOnLastError(er, "Failed to convert security identifier"); + + er = LookupAccountSidW(NULL, sid, userName, &userNameSize, domain, &domainSize, &nameUse); + ExitOnLastError(er, "Failed to lookup security identifier"); + + MsiSetProperty(hInstall, L"AUTHENTICATED_USERS", userName); + ExitOnWin32Error(er, hr, "Failed to set localized Authenticated User name"); + +LExit: + er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; + LocalFree(sid); + return WcaFinalize(er); +} extern "C" BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason, VOID* dummy) { switch (ulReason) { diff --git a/tools/msvs/msi/custom_actions.def b/tools/msvs/msi/custom_actions.def index 5f6b25fc423492..93f2a28f45e45e 100644 --- a/tools/msvs/msi/custom_actions.def +++ b/tools/msvs/msi/custom_actions.def @@ -3,3 +3,4 @@ LIBRARY "custom_actions" EXPORTS SetInstallScope BroadcastEnvironmentUpdate +GetLocalizedUserNames diff --git a/tools/msvs/msi/product.wxs b/tools/msvs/msi/product.wxs index 1aaa11d5ac4c55..ed062c3d74729b 100755 --- a/tools/msvs/msi/product.wxs +++ b/tools/msvs/msi/product.wxs @@ -47,8 +47,6 @@ - - @@ -329,6 +327,12 @@ Execute="immediate" Return="check" /> + + @@ -338,6 +342,7 @@ +