Пожалуйста, обратите внимание, что пользователь заблокирован
C++:
#include <iostream>
#include <Windows.h>
#include <shellapi.h>
bool IsRunningAsAdmin() {
BOOL isAdmin = FALSE;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
&AdministratorsGroup)) {
if (!CheckTokenMembership(nullptr, AdministratorsGroup, &isAdmin)) {
isAdmin = FALSE;
}
FreeSid(AdministratorsGroup);
}
return isAdmin != FALSE;
}
void RestartAsAdmin() {
wchar_t szPath[MAX_PATH];
if (GetModuleFileName(nullptr, szPath, ARRAYSIZE(szPath))) {
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpVerb = L"runas";
sei.lpFile = szPath;
sei.hwnd = nullptr;
sei.nShow = SW_NORMAL;
if (!ShellExecuteEx(&sei)) {
DWORD dwError = GetLastError();
if (dwError == ERROR_CANCELLED) {
std::cout << "Administrative privileges not granted." << std::endl;
}
}
}
exit(0);
}
int main() {
const char* keyPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
HKEY hKey;
if (!IsRunningAsAdmin()) {
RestartAsAdmin();
}
LONG lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyPath, 0, KEY_WRITE, &hKey);
if (lResult == ERROR_SUCCESS) {
DWORD dwData = 0;
lResult = RegSetValueEx(hKey, "EnableLUA", 0, REG_DWORD, (const BYTE*)&dwData, sizeof(dwData));
RegCloseKey(hKey);
if (lResult == ERROR_SUCCESS) {
std::cout << "UAC has been disabled." << std::endl;
} else {
std::cout << "Failed to disable UAC." << std::endl;
}
} else {
std::cout << "Registry key not found. UAC may already be disabled!." << std::endl;
}
return 0;
}