2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/main.c
7 * PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
12 #define MAX_BUFFER_SIZE 4096
14 typedef struct _COMMAND
17 INT (*func
)(INT
, WCHAR
**);
18 // VOID (*help)(INT, WCHAR**);
23 {L
"accounts", cmdAccounts
},
24 {L
"computer", cmdComputer
},
25 {L
"config", cmdConfig
},
26 {L
"continue", cmdContinue
},
27 {L
"file", unimplemented
},
30 {L
"helpmsg", cmdHelpMsg
},
31 {L
"localgroup", cmdLocalGroup
},
33 {L
"session", cmdSession
},
36 {L
"statistics", cmdStatistics
},
38 {L
"syntax", cmdSyntax
},
39 {L
"time", unimplemented
},
42 {L
"view", unimplemented
},
46 HMODULE hModuleNetMsg
= NULL
;
50 PrintPaddedResourceString(
56 nLength
= ConResPuts(StdOut
, uID
);
57 if (nLength
< nPaddedLength
)
58 PrintPadding(L
' ', nPaddedLength
- nLength
);
68 WCHAR szMsgBuffer
[MAX_BUFFER_SIZE
];
70 for (i
= 0; i
< nPaddedLength
; i
++)
72 szMsgBuffer
[nPaddedLength
] = UNICODE_NULL
;
74 ConPuts(StdOut
, szMsgBuffer
);
85 return 3500; // APPERR_3500
87 return 3513; // APPERR_3513
100 va_start(args
, dwMessage
);
102 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
,
113 ConPuts(StdOut
, pBuffer
);
125 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
126 FORMAT_MESSAGE_IGNORE_INSERTS
,
135 ConPuts(StdOut
, pBuffer
);
143 PrintPaddedMessageString(
150 dwLength
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
151 FORMAT_MESSAGE_IGNORE_INSERTS
,
160 ConPuts(StdOut
, pBuffer
);
165 if (dwLength
< (DWORD
)nPaddedLength
)
166 PrintPadding(L
' ', (DWORD
)nPaddedLength
- dwLength
);
174 WCHAR szErrorBuffer
[16];
176 PWSTR pErrorInserts
[2] = {NULL
, NULL
};
178 if (dwError
>= MIN_LANMAN_MESSAGE_ID
&& dwError
<= MAX_LANMAN_MESSAGE_ID
)
180 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
181 FORMAT_MESSAGE_IGNORE_INSERTS
,
190 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
197 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|
198 FORMAT_MESSAGE_IGNORE_INSERTS
,
207 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
213 if (dwError
!= ERROR_SUCCESS
)
215 /* Format insert for the 3514 message */
216 swprintf(szErrorBuffer
, L
"%lu", dwError
);
217 pErrorInserts
[0] = szErrorBuffer
;
219 /* Format and print the 3514 message */
220 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
221 FORMAT_MESSAGE_ARGUMENT_ARRAY
,
227 (va_list *)pErrorInserts
);
230 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
244 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
245 FORMAT_MESSAGE_FROM_HMODULE
|
246 FORMAT_MESSAGE_IGNORE_INSERTS
,
247 GetModuleHandleW(NULL
),
255 ConPuts(StdOut
, pBuffer
);
256 ConPuts(StdOut
, L
"\n");
275 pBuf
= HeapAlloc(GetProcessHeap(), 0, dwLength
- 1);
276 ZeroMemory(lpInput
, dwLength
* sizeof(WCHAR
));
277 hFile
= GetStdHandle(STD_INPUT_HANDLE
);
278 GetConsoleMode(hFile
, &dwOldMode
);
280 SetConsoleMode(hFile
, ENABLE_LINE_INPUT
| (bEcho
? ENABLE_ECHO_INPUT
: 0));
282 ReadFile(hFile
, (PVOID
)pBuf
, dwLength
- 1, &dwRead
, NULL
);
284 MultiByteToWideChar(CP_OEMCP
, 0, pBuf
, dwRead
, lpInput
, dwLength
- 1);
285 HeapFree(GetProcessHeap(), 0, pBuf
);
287 for (p
= lpInput
; *p
; p
++)
296 SetConsoleMode(hFile
, dwOldMode
);
300 int wmain(int argc
, WCHAR
**argv
)
302 WCHAR szDllBuffer
[MAX_PATH
];
307 /* Initialize the Console Standard Streams */
310 /* Load netmsg.dll */
311 GetSystemDirectoryW(szDllBuffer
, ARRAYSIZE(szDllBuffer
));
312 wcscat(szDllBuffer
, L
"\\netmsg.dll");
314 hModuleNetMsg
= LoadLibrary(szDllBuffer
);
315 if (hModuleNetMsg
== NULL
)
317 ConPrintf(StdErr
, L
"Failed to load netmsg.dll\n");
327 /* Scan the command table */
328 for (cmdptr
= cmds
; cmdptr
->name
; cmdptr
++)
330 if (_wcsicmp(argv
[1], cmdptr
->name
) == 0)
332 nResult
= cmdptr
->func(argc
, argv
);
341 PrintMessageString(4381);
342 ConPuts(StdOut
, L
"\n");
343 PrintNetMessage(MSG_NET_SYNTAX
);
346 if (hModuleNetMsg
!= NULL
)
347 FreeLibrary(hModuleNetMsg
);
352 INT
unimplemented(INT argc
, WCHAR
**argv
)
354 ConPuts(StdOut
, L
"This command is not implemented yet\n");