include windows include stdio include userenv void wmain int argc WCHA

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <windows.h>
#include <stdio.h>
#include <userenv.h>
void wmain(int argc, WCHAR *argv[])
{
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {0};
ZeroMemory( &si, sizeof(STARTUPINFO) );
si.cb = sizeof(STARTUPINFO);
si.dwFlags |= STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.cb = sizeof(STARTUPINFO);
if (argc < 4)
{
wprintf(L"Usage: %s [user@domain] [password] [cmd]", argv[0]);
wprintf(L"\nExample: %s adm@my.domain pass \"cmd /c ipconfig >C:\\\\tempdir\\\\output.txt\"", argv[0]);
return;
}
wprintf(L"Executed: %s", argv[3]);
wprintf(L"\n\n");
if (!CreateProcessWithLogonW(argv[1], NULL, argv[2],
LOGON_WITH_PROFILE, NULL, argv[3],
CREATE_UNICODE_ENVIRONMENT, NULL, NULL,
&si, &pi)) wprintf(L"error");
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}