ReactOS 0.4.16-dev-329-g9223134
cmdSession.c File Reference
#include "net.h"
Include dependency graph for cmdSession.c:

Go to the source code of this file.

Functions

static VOID SecondsToDurationString (_Out_ PWSTR DurationString, _In_ size_t DurationStringSize, _In_ DWORD dwDuration)
 
NET_API_STATUS EnumSessions (_In_ PWSTR pszComputerName, _In_ BOOL bList)
 
INT cmdSession (_In_ INT argc, _In_ WCHAR **argv)
 

Function Documentation

◆ cmdSession()

INT cmdSession ( _In_ INT  argc,
_In_ WCHAR **  argv 
)

Definition at line 91 of file cmdSession.c.

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}
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
#define StdOut
Definition: fc.c:14
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
NET_API_STATUS EnumSessions(_In_ PWSTR pszComputerName, _In_ BOOL bList)
Definition: cmdSession.c:29
#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
NET_API_STATUS WINAPI NetSessionDel(_In_opt_ LMSTR servername, _In_opt_ LMSTR UncClientName, _In_opt_ LMSTR username)
Definition: srvsvc.c:612
unsigned int BOOL
Definition: ntddk_ex.h:94
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 NERR_Success
Definition: lmerr.h:5
#define argv
Definition: mplay32.c:18
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58

◆ EnumSessions()

NET_API_STATUS EnumSessions ( _In_ PWSTR  pszComputerName,
_In_ BOOL  bList 
)

Definition at line 29 of file cmdSession.c.

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}
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:63
static VOID SecondsToDurationString(_Out_ PWSTR DurationString, _In_ size_t DurationStringSize, _In_ DWORD dwDuration)
Definition: cmdSession.c:12
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
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 long DWORD
Definition: ntddk_ex.h:95
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
PVOID pBuffer
unsigned char * LPBYTE
Definition: typedefs.h:53
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by cmdSession(), and DECLARE_INTERFACE_().

◆ SecondsToDurationString()

static VOID SecondsToDurationString ( _Out_ PWSTR  DurationString,
_In_ size_t  DurationStringSize,
_In_ DWORD  dwDuration 
)
static

Definition at line 12 of file cmdSession.c.

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}
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530

Referenced by EnumSessions().