ReactOS 0.4.15-dev-7961-gdcf9eb0
cmdSession.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/cmdSession.c
5 * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
6 */
7
8#include "net.h"
9
10static
11VOID
13 _Out_ PWSTR DurationString,
14 _In_ size_t DurationStringSize,
15 _In_ DWORD dwDuration)
16{
17 DWORD dwHours, dwRemainingSeconds, dwMinutes, dwSeconds;
18
19 dwHours = dwDuration / 3600;
20 dwRemainingSeconds = dwDuration % 3600;
21 dwMinutes = dwRemainingSeconds / 60;
22 dwSeconds = dwRemainingSeconds % 60;
23
24 StringCchPrintfW(DurationString, DurationStringSize, L"%02lu:%02lu:%02lu", dwHours, dwMinutes, dwSeconds);
25}
26
27
30 _In_ PWSTR pszComputerName,
31 _In_ BOOL bList)
32{
34 WCHAR DurationBuffer[10];
35 DWORD dwRead = 0, dwTotal = 0, i;
36 DWORD ResumeHandle = 0;
38
39 Status = NetSessionEnum(pszComputerName,
40 NULL,
41 NULL,
42 2,
43 (LPBYTE*)&pBuffer,
45 &dwRead,
46 &dwTotal,
47 &ResumeHandle);
49 {
50// PrintMessageStringV(3502, Status);
51 ConPrintf(StdOut, L"System error %lu has occurred.\n\n", Status);
52 return Status;
53 }
54
55 if (dwTotal == 0)
56 {
58 }
59 else
60 {
61 ConPuts(StdOut, L"\n");
63 PrintPadding(L'-', 79);
64 ConPuts(StdOut, L"\n");
65
66 for (i = 0; i < dwRead; i++)
67 {
68 if (pBuffer[i].sesi2_cname)
69 {
70 SecondsToDurationString(DurationBuffer,
71 ARRAYSIZE(DurationBuffer),
72 pBuffer[i].sesi2_idle_time);
73
74 ConPrintf(StdOut, L"%-22.22s %-20.20s %-17.17s %-5lu %-8.8s\n",
75 pBuffer[i].sesi2_cname,
76 pBuffer[i].sesi2_username,
77 pBuffer[i].sesi2_cltype_name,
78 pBuffer[i].sesi2_num_opens,
79 DurationBuffer);
80 }
81 }
82 }
83
85
86 return NERR_Success;
87}
88
89
90INT
93 _In_ WCHAR **argv)
94{
95 PWSTR pszComputerName = NULL;
96 BOOL bList = FALSE;
97 BOOL bDelete = FALSE;
98 INT i = 0;
100 INT result = 0;
101
102 for (i = 2; i < argc; i++)
103 {
104 if (argv[i][0] == L'\\' && argv[i][1] == L'\\' && pszComputerName == NULL)
105 {
106 pszComputerName = argv[i];
107 i++;
108 }
109 else if (_wcsicmp(argv[i], L"/list") == 0)
110 {
111 bList = TRUE;
112 continue;
113 }
114 else if (_wcsicmp(argv[i], L"/delete") == 0)
115 {
116 bDelete = TRUE;
117 continue;
118 }
119 else if (_wcsicmp(argv[i], L"/help") == 0)
120 {
121 PrintMessageString(4381);
122 ConPuts(StdOut, L"\n");
123 PrintNetMessage(MSG_SESSION_SYNTAX);
124 PrintNetMessage(MSG_SESSION_HELP);
125 return 0;
126 }
127 else
128 {
129 PrintMessageString(4381);
130 ConPuts(StdOut, L"\n");
131 PrintNetMessage(MSG_SESSION_SYNTAX);
132 return 1;
133 }
134 }
135
136 if (bDelete)
137 Status = NetSessionDel(pszComputerName, NULL, NULL);
138 else
139 Status = EnumSessions(pszComputerName, bList);
140
141 if (Status == NERR_Success)
142 {
144 }
145 else
146 {
148 result = 1;
149 }
150
151 return result;
152}
153
154/* EOF */
static int argc
Definition: ServiceArgs.c:12
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:63
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
INT cmdSession(_In_ INT argc, _In_ WCHAR **argv)
Definition: cmdSession.c:91
static VOID SecondsToDurationString(_Out_ PWSTR DurationString, _In_ size_t DurationStringSize, _In_ DWORD dwDuration)
Definition: cmdSession.c:12
NET_API_STATUS EnumSessions(_In_ PWSTR pszComputerName, _In_ BOOL bList)
Definition: cmdSession.c:29
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
NET_API_STATUS WINAPI NetSessionDel(_In_opt_ LMSTR servername, _In_opt_ LMSTR UncClientName, _In_opt_ LMSTR username)
Definition: srvsvc.c:612
NET_API_STATUS WINAPI NetSessionEnum(_In_opt_ LMSTR servername, _In_opt_ LMSTR UncClientName, _In_opt_ LMSTR username, _In_ DWORD level, _Out_ LPBYTE *bufptr, _In_ DWORD prefmaxlen, _Out_ LPDWORD entriesread, _Out_ LPDWORD totalentries, _Inout_ LPDWORD resume_handle)
Definition: srvsvc.c:640
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
GLuint64EXT * result
Definition: glext.h:11304
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
#define NERR_Success
Definition: lmerr.h:5
#define argv
Definition: mplay32.c:18
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define L(x)
Definition: ntvdm.h:50
PVOID pBuffer
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Deprecated header file that includes net_sockets.h.
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
__wchar_t WCHAR
Definition: xmlstorage.h:180