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
},
32 {L
"name", unimplemented
},
34 {L
"print", unimplemented
},
35 {L
"send", unimplemented
},
36 {L
"session", unimplemented
},
37 {L
"share", unimplemented
},
39 {L
"statistics", cmdStatistics
},
41 {L
"time", unimplemented
},
44 {L
"view", unimplemented
},
48 HMODULE hModuleNetMsg
= NULL
;
52 PrintPaddedResourceString(
58 nLength
= ConResPuts(StdOut
, uID
);
59 if (nLength
< nPaddedLength
)
60 PrintPadding(L
' ', nPaddedLength
- nLength
);
70 WCHAR szMsgBuffer
[MAX_BUFFER_SIZE
];
72 for (i
= 0; i
< nPaddedLength
; i
++)
74 szMsgBuffer
[nPaddedLength
] = UNICODE_NULL
;
76 ConPuts(StdOut
, szMsgBuffer
);
84 WCHAR szErrorBuffer
[16];
86 PWSTR pErrorInserts
[2] = {NULL
, NULL
};
88 if (dwError
>= MIN_LANMAN_MESSAGE_ID
&& dwError
<= MAX_LANMAN_MESSAGE_ID
)
90 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
91 FORMAT_MESSAGE_IGNORE_INSERTS
,
100 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
107 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|
108 FORMAT_MESSAGE_IGNORE_INSERTS
,
117 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
123 if (dwError
!= ERROR_SUCCESS
)
125 /* Format insert for the 3514 message */
126 swprintf(szErrorBuffer
, L
"%lu", dwError
);
127 pErrorInserts
[0] = szErrorBuffer
;
129 /* Format and print the 3514 message */
130 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
131 FORMAT_MESSAGE_ARGUMENT_ARRAY
,
137 (va_list *)pErrorInserts
);
140 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
154 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
155 FORMAT_MESSAGE_FROM_HMODULE
|
156 FORMAT_MESSAGE_IGNORE_INSERTS
,
157 GetModuleHandleW(NULL
),
165 ConPrintf(StdOut
, L
"%s\n", pBuffer
);
184 pBuf
= HeapAlloc(GetProcessHeap(), 0, dwLength
- 1);
185 ZeroMemory(lpInput
, dwLength
* sizeof(WCHAR
));
186 hFile
= GetStdHandle(STD_INPUT_HANDLE
);
187 GetConsoleMode(hFile
, &dwOldMode
);
189 SetConsoleMode(hFile
, ENABLE_LINE_INPUT
| (bEcho
? ENABLE_ECHO_INPUT
: 0));
191 ReadFile(hFile
, (PVOID
)pBuf
, dwLength
- 1, &dwRead
, NULL
);
193 MultiByteToWideChar(CP_OEMCP
, 0, pBuf
, dwRead
, lpInput
, dwLength
- 1);
194 HeapFree(GetProcessHeap(), 0, pBuf
);
196 for (p
= lpInput
; *p
; p
++)
205 SetConsoleMode(hFile
, dwOldMode
);
209 int wmain(int argc
, WCHAR
**argv
)
211 WCHAR szDllBuffer
[MAX_PATH
];
216 /* Initialize the Console Standard Streams */
219 /* Load netmsg.dll */
220 GetSystemDirectoryW(szDllBuffer
, ARRAYSIZE(szDllBuffer
));
221 wcscat(szDllBuffer
, L
"\\netmsg.dll");
223 hModuleNetMsg
= LoadLibrary(szDllBuffer
);
224 if (hModuleNetMsg
== NULL
)
226 ConPrintf(StdErr
, L
"Failed to load netmsg.dll\n");
236 /* Scan the command table */
237 for (cmdptr
= cmds
; cmdptr
->name
; cmdptr
++)
239 if (_wcsicmp(argv
[1], cmdptr
->name
) == 0)
241 nResult
= cmdptr
->func(argc
, argv
);
249 PrintNetMessage(MSG_NET_SYNTAX
);
251 if (hModuleNetMsg
!= NULL
)
252 FreeLibrary(hModuleNetMsg
);
257 INT
unimplemented(INT argc
, WCHAR
**argv
)
259 ConPuts(StdOut
, L
"This command is not implemented yet\n");