mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-29 08:29:10 +01:00
Compare commits
1 Commits
jay/lsv2
...
stefa/test
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d1f7c03c3 |
@@ -138,6 +138,9 @@
|
||||
<Custom Action="CheckGPO" After="InstallInitialize">
|
||||
NOT Installed
|
||||
</Custom>
|
||||
<Custom Action="CheckAdministratorConstraints" After="InstallInitialize">
|
||||
NOT Installed
|
||||
</Custom>
|
||||
<Custom Action="ApplyModulesRegistryChangeSets" After="InstallFiles">
|
||||
NOT Installed
|
||||
</Custom>
|
||||
@@ -347,6 +350,13 @@
|
||||
DllEntry="CheckGPOCA"
|
||||
/>
|
||||
|
||||
<CustomAction Id="CheckAdministratorConstraints"
|
||||
Return="check"
|
||||
Impersonate="yes"
|
||||
BinaryKey="PTCustomActions"
|
||||
DllEntry="CheckAdministratorConstraintsCA"
|
||||
/>
|
||||
|
||||
<!-- Close 'PowerToys.exe' before uninstall-->
|
||||
<Property Id="MSIRESTARTMANAGERCONTROL" Value="DisableShutdown" />
|
||||
<Property Id="MSIFASTINSTALL" Value="DisableShutdown" />
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Management.Deployment.h>
|
||||
|
||||
#include <wtsapi32.h>
|
||||
#include <processthreadsapi.h>
|
||||
#include <sddl.h>
|
||||
#include <UserEnv.h>
|
||||
#include <winnt.h>
|
||||
#include <wtsapi32.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -93,6 +94,65 @@ BOOL IsLocalSystem()
|
||||
return bSystem;
|
||||
}
|
||||
|
||||
bool GetUserSid(const wchar_t* username, PSID& sid)
|
||||
{
|
||||
DWORD sidSize = 0;
|
||||
DWORD domainNameSize = 0;
|
||||
SID_NAME_USE sidNameUse;
|
||||
|
||||
LookupAccountName(nullptr, username, nullptr, &sidSize, nullptr, &domainNameSize, &sidNameUse);
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
Logger::error("Failed to get buffer sizes");
|
||||
return false;
|
||||
}
|
||||
|
||||
sid = LocalAlloc(LPTR, sidSize);
|
||||
LPWSTR domainName = static_cast<LPWSTR>(LocalAlloc(LPTR, domainNameSize * sizeof(wchar_t)));
|
||||
|
||||
if (!LookupAccountNameW(nullptr, username, sid, &sidSize, domainName, &domainNameSize, &sidNameUse))
|
||||
{
|
||||
Logger::error("Failed to lookup account name");
|
||||
LocalFree(sid);
|
||||
LocalFree(domainName);
|
||||
return false;
|
||||
}
|
||||
|
||||
LocalFree(domainName);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::wstring GetCurrentUserSid()
|
||||
{
|
||||
wchar_t username[UNLEN + 1];
|
||||
DWORD usernameSize = UNLEN + 1;
|
||||
|
||||
std::wstring result;
|
||||
if (!GetUserNameW(username, &usernameSize))
|
||||
{
|
||||
Logger::error("Failed to get the current user name");
|
||||
return result;
|
||||
}
|
||||
|
||||
PSID sid;
|
||||
if (GetUserSid(username, sid))
|
||||
{
|
||||
LPWSTR sidString;
|
||||
if (ConvertSidToStringSid(sid, &sidString))
|
||||
{
|
||||
result = sidString;
|
||||
LocalFree(sidString);
|
||||
}
|
||||
LocalFree(sid);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::error(L"Failed to get SID for user \"");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL ImpersonateLoggedInUserAndDoSomething(std::function<bool(HANDLE userToken)> action)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
@@ -262,6 +322,29 @@ LExit:
|
||||
return WcaFinalize(er);
|
||||
}
|
||||
|
||||
UINT __stdcall CheckAdministratorConstraintsCA(MSIHANDLE hInstall)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
std::wstring asd;
|
||||
|
||||
hr = WcaInitialize(hInstall, "CheckAdministratorConstraintsCA");
|
||||
ExitOnFailure(hr, "Failed to initialize");
|
||||
|
||||
LPWSTR currentScope = nullptr;
|
||||
hr = WcaGetProperty(L"InstallScope", ¤tScope);
|
||||
|
||||
if (std::wstring{ currentScope } == L"perUser")
|
||||
{
|
||||
}
|
||||
|
||||
asd = GetCurrentUserSid();
|
||||
MessageBox(NULL, asd.c_str(), asd.c_str(), NULL);
|
||||
|
||||
LExit:
|
||||
UINT er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
||||
return WcaFinalize(er);
|
||||
}
|
||||
|
||||
UINT __stdcall ApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
@@ -3,6 +3,7 @@ LIBRARY "PowerToysSetupCustomActions"
|
||||
EXPORTS
|
||||
LaunchPowerToysCA
|
||||
CheckGPOCA
|
||||
CheckAdministratorConstraintsCA
|
||||
ApplyModulesRegistryChangeSetsCA
|
||||
DetectPrevInstallPathCA
|
||||
RemoveScheduledTasksCA
|
||||
|
||||
Reference in New Issue
Block a user