Last active
October 23, 2022 05:27
-
-
Save TrQ-Hoan/dbb7871850fd180741dcb65cf7e84fcc to your computer and use it in GitHub Desktop.
Administator CMD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
// cl.exe /D_X86_ /EHsc /MT admin.c /link /NODEFAULTLIB /ENTRY:main /MANIFEST /MANIFESTUAC:level='requireAdministrator' /MACHINE:X86 kernel32.lib libcmt.lib | |
// mt.exe -manifest admin.exe.manifest -outputresource:admin.exe;#1 | |
int main() { | |
int const path_len = 32767; | |
wchar_t path[32767] = {0}; | |
DWORD err = 0; | |
STARTUPINFOW si; | |
PROCESS_INFORMATION pi; | |
LPWSTR imgPath = L"C:\\Windows\\System32\\cmd.exe"; | |
ZeroMemory(&si, sizeof(si)); | |
si.cb = sizeof(si); | |
ZeroMemory(&pi, sizeof(pi)); | |
if (!GetCurrentDirectoryW(path_len, path)) { | |
err = GetLastError(); | |
} | |
if (err == 0 && !CreateProcessW(imgPath, NULL, NULL, NULL, FALSE, 0, NULL, path, &si, &pi)) { | |
err = GetLastError(); | |
} | |
return err; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment