-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathmain.c
91 lines (78 loc) · 2.07 KB
/
main.c
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
///////////////////////////////////////////////////////////////////////////////
//
// Module Name:
//
// main.c
//
// Abstract:
//
// Main file for KexCfg.
//
// Author:
//
// vxiiduu (09-Feb-2024)
//
// Environment:
//
// Win32 mode. Sometimes this program is run as Administrator, sometimes
// as a standard account, sometimes as the local SYSTEM account.
//
// Revision History:
//
// vxiiduu 09-Feb-2024 Initial creation.
//
///////////////////////////////////////////////////////////////////////////////
#include "kexcfg.h"
#include <WtsApi32.h>
BOOLEAN Interactive;
ULONG SessionId;
VOID EntryPoint(
VOID)
{
PCWSTR CommandLine;
//
// When we are running as the local SYSTEM account, we cannot just call
// MessageBox to display information to the user, because processes running
// as the SYSTEM account run on a non-interactive session for security
// reasons (on Windows Vista and later).
//
// The WTSSendMessage function allows us to display a message box on the
// interactive desktop. But in order to do so, we need to have a session ID,
// which we can determine by enumerating all sessions and finding the first
// one which is "active" (i.e. logged in with a user).
//
Interactive = RunningInInteractiveWindowStation();
if (Interactive) {
SessionId = WTS_CURRENT_SESSION;
} else {
BOOLEAN Success;
PWTS_SESSION_INFO SessionInfo;
ULONG NumberOfSessions;
Success = WTSEnumerateSessions(
WTS_CURRENT_SERVER,
0, 1,
&SessionInfo,
&NumberOfSessions);
try {
ULONG Index;
for (Index = 0; Index < NumberOfSessions; ++Index) {
if (SessionInfo[Index].State == WTSActive) {
SessionId = SessionInfo[Index].SessionId;
}
}
} finally {
WTSFreeMemory(SessionInfo);
}
}
//
// If we have no command line options, then we will open the GUI.
// Otherwise we will process and act upon our command line arguments.
//
CommandLine = GetCommandLineWithoutImageName();;
if (CommandLine[0] == '\0') {
KexCfgOpenGUI();
} else {
KexCfgHandleCommandLine(CommandLine);
}
ExitProcess(STATUS_SUCCESS);
}