tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[NET] Add the net session command
Eric Kohl
2 years ago
a38b133d
b0b40ce5
+159
-1
4 changed files
expand all
collapse all
unified
split
base
applications
network
net
CMakeLists.txt
cmdSession.c
main.c
net.h
+1
base/applications/network/net/CMakeLists.txt
reviewed
···
14
14
cmdHelpMsg.c
15
15
cmdLocalGroup.c
16
16
cmdPause.c
17
17
+
cmdSession.c
17
18
cmdShare.c
18
19
cmdStart.c
19
20
cmdStatistics.c
+154
base/applications/network/net/cmdSession.c
reviewed
···
1
1
+
/*
2
2
+
* COPYRIGHT: See COPYING in the top level directory
3
3
+
* PROJECT: ReactOS net command
4
4
+
* FILE: base/applications/network/net/cmdSession.c
5
5
+
* PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
6
6
+
*/
7
7
+
8
8
+
#include "net.h"
9
9
+
10
10
+
static
11
11
+
VOID
12
12
+
SecondsToDurationString(
13
13
+
_Out_ PWSTR DurationString,
14
14
+
_In_ size_t DurationStringSize,
15
15
+
_In_ DWORD dwDuration)
16
16
+
{
17
17
+
DWORD dwHours, dwRemainingSeconds, dwMinutes, dwSeconds;
18
18
+
19
19
+
dwHours = dwDuration / 3600;
20
20
+
dwRemainingSeconds = dwDuration % 3600;
21
21
+
dwMinutes = dwRemainingSeconds / 60;
22
22
+
dwSeconds = dwRemainingSeconds % 60;
23
23
+
24
24
+
StringCchPrintfW(DurationString, DurationStringSize, L"%02lu:%02lu:%02lu", dwHours, dwMinutes, dwSeconds);
25
25
+
}
26
26
+
27
27
+
28
28
+
NET_API_STATUS
29
29
+
EnumSessions(
30
30
+
_In_ PWSTR pszComputerName,
31
31
+
_In_ BOOL bList)
32
32
+
{
33
33
+
PSESSION_INFO_2 pBuffer = NULL;
34
34
+
WCHAR DurationBuffer[10];
35
35
+
DWORD dwRead = 0, dwTotal = 0, i;
36
36
+
DWORD ResumeHandle = 0;
37
37
+
NET_API_STATUS Status;
38
38
+
39
39
+
Status = NetSessionEnum(pszComputerName,
40
40
+
NULL,
41
41
+
NULL,
42
42
+
2,
43
43
+
(LPBYTE*)&pBuffer,
44
44
+
MAX_PREFERRED_LENGTH,
45
45
+
&dwRead,
46
46
+
&dwTotal,
47
47
+
&ResumeHandle);
48
48
+
if ((Status != NERR_Success) && (Status != ERROR_MORE_DATA))
49
49
+
{
50
50
+
// PrintMessageStringV(3502, Status);
51
51
+
ConPrintf(StdOut, L"System error %lu has occurred.\n\n", Status);
52
52
+
return Status;
53
53
+
}
54
54
+
55
55
+
if (dwTotal == 0)
56
56
+
{
57
57
+
PrintMessageString(3683);
58
58
+
}
59
59
+
else
60
60
+
{
61
61
+
ConPuts(StdOut, L"\n");
62
62
+
PrintMessageString(4750);
63
63
+
PrintPadding(L'-', 79);
64
64
+
ConPuts(StdOut, L"\n");
65
65
+
66
66
+
for (i = 0; i < dwRead; i++)
67
67
+
{
68
68
+
if (pBuffer[i].sesi2_cname)
69
69
+
{
70
70
+
SecondsToDurationString(DurationBuffer,
71
71
+
ARRAYSIZE(DurationBuffer),
72
72
+
pBuffer[i].sesi2_idle_time);
73
73
+
74
74
+
ConPrintf(StdOut, L"%-22.22s %-20.20s %-17.17s %-5lu %-8.8s\n",
75
75
+
pBuffer[i].sesi2_cname,
76
76
+
pBuffer[i].sesi2_username,
77
77
+
pBuffer[i].sesi2_cltype_name,
78
78
+
pBuffer[i].sesi2_num_opens,
79
79
+
DurationBuffer);
80
80
+
}
81
81
+
}
82
82
+
}
83
83
+
84
84
+
NetApiBufferFree(pBuffer);
85
85
+
86
86
+
return NERR_Success;
87
87
+
}
88
88
+
89
89
+
90
90
+
INT
91
91
+
cmdSession(
92
92
+
_In_ INT argc,
93
93
+
_In_ WCHAR **argv)
94
94
+
{
95
95
+
PWSTR pszComputerName = NULL;
96
96
+
BOOL bList = FALSE;
97
97
+
BOOL bDelete = FALSE;
98
98
+
INT i = 0;
99
99
+
NET_API_STATUS Status;
100
100
+
INT result = 0;
101
101
+
102
102
+
for (i = 2; i < argc; i++)
103
103
+
{
104
104
+
if (argv[i][0] == L'\\' && argv[i][1] == L'\\' && pszComputerName == NULL)
105
105
+
{
106
106
+
pszComputerName = argv[i];
107
107
+
i++;
108
108
+
}
109
109
+
else if (_wcsicmp(argv[i], L"/list") == 0)
110
110
+
{
111
111
+
bList = TRUE;
112
112
+
continue;
113
113
+
}
114
114
+
else if (_wcsicmp(argv[i], L"/delete") == 0)
115
115
+
{
116
116
+
bDelete = TRUE;
117
117
+
continue;
118
118
+
}
119
119
+
else if (_wcsicmp(argv[i], L"/help") == 0)
120
120
+
{
121
121
+
PrintMessageString(4381);
122
122
+
ConPuts(StdOut, L"\n");
123
123
+
PrintNetMessage(MSG_SESSION_SYNTAX);
124
124
+
PrintNetMessage(MSG_SESSION_HELP);
125
125
+
return 0;
126
126
+
}
127
127
+
else
128
128
+
{
129
129
+
PrintMessageString(4381);
130
130
+
ConPuts(StdOut, L"\n");
131
131
+
PrintNetMessage(MSG_SESSION_SYNTAX);
132
132
+
return 1;
133
133
+
}
134
134
+
}
135
135
+
136
136
+
if (bDelete)
137
137
+
Status = NetSessionDel(pszComputerName, NULL, NULL);
138
138
+
else
139
139
+
Status = EnumSessions(pszComputerName, bList);
140
140
+
141
141
+
if (Status == NERR_Success)
142
142
+
{
143
143
+
PrintErrorMessage(ERROR_SUCCESS);
144
144
+
}
145
145
+
else
146
146
+
{
147
147
+
PrintErrorMessage(Status);
148
148
+
result = 1;
149
149
+
}
150
150
+
151
151
+
return result;
152
152
+
}
153
153
+
154
154
+
/* EOF */
+1
-1
base/applications/network/net/main.c
reviewed
···
30
30
{L"helpmsg", cmdHelpMsg},
31
31
{L"localgroup", cmdLocalGroup},
32
32
{L"pause", cmdPause},
33
33
-
{L"session", unimplemented},
33
33
+
{L"session", cmdSession},
34
34
{L"share", cmdShare},
35
35
{L"start", cmdStart},
36
36
{L"statistics", cmdStatistics},
+3
base/applications/network/net/net.h
reviewed
···
22
22
#include <lm.h>
23
23
#include <ndk/rtlfuncs.h>
24
24
25
25
+
#include <strsafe.h>
26
26
+
25
27
#include <conutils.h>
26
28
27
29
#include <net_msg.h>
···
82
84
INT cmdHelpMsg(INT argc, WCHAR **argv);
83
85
INT cmdLocalGroup(INT argc, WCHAR **argv);
84
86
INT cmdPause(INT argc, WCHAR **argv);
87
87
+
INT cmdSession(INT argc, WCHAR **argv);
85
88
INT cmdShare(INT argc, WCHAR **argv);
86
89
INT cmdStart(INT argc, WCHAR **argv);
87
90
INT cmdStatistics(INT argc, WCHAR **argv);