Reactos

[NET] Add the net session command

+159 -1
+1
base/applications/network/net/CMakeLists.txt
··· 14 14 cmdHelpMsg.c 15 15 cmdLocalGroup.c 16 16 cmdPause.c 17 + cmdSession.c 17 18 cmdShare.c 18 19 cmdStart.c 19 20 cmdStatistics.c
+154
base/applications/network/net/cmdSession.c
··· 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 + 10 + static 11 + VOID 12 + SecondsToDurationString( 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 + 28 + NET_API_STATUS 29 + EnumSessions( 30 + _In_ PWSTR pszComputerName, 31 + _In_ BOOL bList) 32 + { 33 + PSESSION_INFO_2 pBuffer = NULL; 34 + WCHAR DurationBuffer[10]; 35 + DWORD dwRead = 0, dwTotal = 0, i; 36 + DWORD ResumeHandle = 0; 37 + NET_API_STATUS Status; 38 + 39 + Status = NetSessionEnum(pszComputerName, 40 + NULL, 41 + NULL, 42 + 2, 43 + (LPBYTE*)&pBuffer, 44 + MAX_PREFERRED_LENGTH, 45 + &dwRead, 46 + &dwTotal, 47 + &ResumeHandle); 48 + if ((Status != NERR_Success) && (Status != ERROR_MORE_DATA)) 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 + { 57 + PrintMessageString(3683); 58 + } 59 + else 60 + { 61 + ConPuts(StdOut, L"\n"); 62 + PrintMessageString(4750); 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 + 84 + NetApiBufferFree(pBuffer); 85 + 86 + return NERR_Success; 87 + } 88 + 89 + 90 + INT 91 + cmdSession( 92 + _In_ INT argc, 93 + _In_ WCHAR **argv) 94 + { 95 + PWSTR pszComputerName = NULL; 96 + BOOL bList = FALSE; 97 + BOOL bDelete = FALSE; 98 + INT i = 0; 99 + NET_API_STATUS Status; 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 + { 143 + PrintErrorMessage(ERROR_SUCCESS); 144 + } 145 + else 146 + { 147 + PrintErrorMessage(Status); 148 + result = 1; 149 + } 150 + 151 + return result; 152 + } 153 + 154 + /* EOF */
+1 -1
base/applications/network/net/main.c
··· 30 30 {L"helpmsg", cmdHelpMsg}, 31 31 {L"localgroup", cmdLocalGroup}, 32 32 {L"pause", cmdPause}, 33 - {L"session", unimplemented}, 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
··· 22 22 #include <lm.h> 23 23 #include <ndk/rtlfuncs.h> 24 24 25 + #include <strsafe.h> 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 + 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);