Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- int main ()
- {
- HMODULE hAdvAPIDLL = LoadLibraryW (L"advapi32legacy.dll");
- // Should FreeLibrary later
- if (hAdvAPIDLL == 0) {
- std::cout << "LoadLibraryW failed with code " << std::hex << GetLastError () << std::endl;
- return -1;
- }
- std::cout << "Got handle to advapi32legacy.dll (loaded @ address 0x" << std::hex << hAdvAPIDLL << ")" << std::endl;
- using FnCreateProcessWithLogonW = BOOL (*) (LPCWSTR,
- LPCWSTR,
- LPCWSTR,
- DWORD,
- LPCWSTR,
- LPWSTR,
- DWORD,
- LPVOID,
- LPCWSTR,
- LPSTARTUPINFOW,
- LPPROCESS_INFORMATION);
- FnCreateProcessWithLogonW pCreateProcessWithLogonW =
- reinterpret_cast<FnCreateProcessWithLogonW> (GetProcAddress (hAdvAPIDLL, "CreateProcessWithLogonW"));
- if (pCreateProcessWithLogonW == nullptr) {
- std::cout << "Unable to locate \"CreateProcessWithLogonW\" in advapi32legacy.dll, errorcode:" << std::hex <<
- GetLastError () << std::endl;
- return -1;
- }
- std::cout << "Located \"CreateProcessWithLogonW\" in advapi32legacy.dll @ " << std::hex << pCreateProcessWithLogonW << std::endl;
- STARTUPINFOW si = {};
- si.cb = sizeof si;
- PROCESS_INFORMATION pi = {};
- BOOL success = pCreateProcessWithLogonW (L"Administrator",
- nullptr,
- L"yourpasswordgoeshere",
- 0,
- L"devcon.exe",
- LR"(dp_add "c:\Data\Users\DefaultAccount\net7800-arm-n650f.inf")", // meh
- 0,
- nullptr,
- nullptr,
- &si,
- &pi);
- // Should CloseHandle on pi.hProcess and pi.hThread later
- if (success != FALSE) {
- std::cout << "Successfully created process!" << std::endl;
- std::cout << "Waiting for process..." << std::endl;
- switch (WaitForSingleObject (pi.hProcess, INFINITE)) {
- case WAIT_OBJECT_0: {
- DWORD exitCode;
- if (GetExitCodeProcess (pi.hProcess, &exitCode) != FALSE)
- std::cout << "Process exited with code 0x" << std::hex << exitCode << std::endl;
- else
- std::cout << "Process exited with unknown exit code!" << std::endl;
- break;
- }
- default:
- std::cout << "Unexpected value returned from WaitForSingleObject!" << std::endl;
- }
- } else {
- std::cout << "Failed to create process! Errorcode: " << std::hex << "0x" << GetLastError () << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement