ReactOS 0.4.15-dev-8102-g108db8f
gettype.c File Reference
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <lm.h>
#include <shellapi.h>
Include dependency graph for gettype.c:

Go to the source code of this file.

Enumerations

enum  {
  GETTYPE_ROLE = 0x001 , GETTYPE_HELP = 0x002 , GETTYPE_SP = 0x004 , GETTYPE_VER = 0x008 ,
  GETTYPE_MINV = 0x010 , GETTYPE_MAJV = 0x020 , GETTYPE_TYPE = 0x040 , GETTYPE_BUILD = 0x080
}
 

Functions

INT GetVersionNumber (BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
 
INT GetMajValue (BOOL Major, BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
 
INT GetSystemRole (BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
 
INT GetServicePack (BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102, TCHAR *Server)
 
INT GetBuildNumber (BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
 
INT GetType (BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
 
VOID GetBasicInfo (LPOSVERSIONINFOEX osvi, TCHAR *HostName, TCHAR *OSName, TCHAR *Version, TCHAR *Role, TCHAR *Components)
 
INT _tmain (VOID)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
GETTYPE_ROLE 
GETTYPE_HELP 
GETTYPE_SP 
GETTYPE_VER 
GETTYPE_MINV 
GETTYPE_MAJV 
GETTYPE_TYPE 
GETTYPE_BUILD 

Definition at line 21 of file gettype.c.

22{
23 GETTYPE_ROLE = 0x001,
24 GETTYPE_HELP = 0x002,
25 GETTYPE_SP = 0x004,
26 GETTYPE_VER = 0x008,
27 GETTYPE_MINV = 0x010,
28 GETTYPE_MAJV = 0x020,
29 GETTYPE_TYPE = 0x040,
30 GETTYPE_BUILD = 0x080
31};
@ GETTYPE_HELP
Definition: gettype.c:24
@ GETTYPE_BUILD
Definition: gettype.c:30
@ GETTYPE_ROLE
Definition: gettype.c:23
@ GETTYPE_MAJV
Definition: gettype.c:28
@ GETTYPE_VER
Definition: gettype.c:26
@ GETTYPE_MINV
Definition: gettype.c:27
@ GETTYPE_SP
Definition: gettype.c:25
@ GETTYPE_TYPE
Definition: gettype.c:29

Function Documentation

◆ _tmain()

INT _tmain ( VOID  )

Definition at line 229 of file gettype.c.

230{
231 DWORD Operations = 0;
232 INT ret = 255;
233 INT i = 0;
234 INT argc = 0;
235 /* True if the target is local host */
236 BOOL bLocal = TRUE;
237 DWORD nStatus = 0;
238 TCHAR ServerName[32];
239 TCHAR RemoteResource[32];
240 TCHAR UserName[32] = _T("");
241 TCHAR Password[32] = _T("");
243 LPSERVER_INFO_102 pBuf102 = NULL;
244 LPTSTR * argv;
246 pBuf102 = (LPSERVER_INFO_102)malloc(sizeof(LPSERVER_INFO_102));
247
248 /* Get the command line correctly since it is unicode */
250
251
252 /* Process flags */
253 if(argc)
254 {
255 for (i = 1; i < argc; i++)
256 {
257 if(!_tcsicmp(argv[i], _T("/ROLE")) && !Operations)
258 Operations |= GETTYPE_ROLE;
259 else if(!_tcsicmp(argv[i], _T("/VER")) && !Operations)
260 Operations |= GETTYPE_VER;
261 else if(!_tcsicmp(argv[i], _T("/MAJV")) && !Operations)
262 Operations |= GETTYPE_MAJV;
263 else if(!_tcsicmp(argv[i], _T("/MINV")) && !Operations)
264 Operations |= GETTYPE_MINV;
265 else if(!_tcsicmp(argv[i], _T("/SP")) && !Operations)
266 Operations |= GETTYPE_SP;
267 else if(!_tcsicmp(argv[i], _T("/BUILD")) && !Operations)
268 Operations |= GETTYPE_BUILD;
269 else if(!_tcsicmp(argv[i], _T("/TYPE")) && !Operations)
270 Operations |= GETTYPE_TYPE;
271 else if(!_tcsicmp(argv[i], _T("/?")) && !Operations)
272 Operations |= GETTYPE_HELP;
273 else if(!_tcsicmp(argv[i], _T("/S")) && i + 1 < argc)
274 {
275 _tcscpy(ServerName,argv[++i]);
276 bLocal = FALSE;
277 }
278 else if(!_wcsicmp(argv[i], L"/U") && i + 1 < argc)
279 _tcscpy(UserName,argv[++i]);
280 else if(!_wcsicmp(argv[i], L"/P") && i + 1 < argc)
282 else
283 {
284 wprintf(L"Error in paramters, please see usage\n");
285 return 255;
286 }
287 }
288 }
289
290 /* Some debug info */
291 //_tprintf(_T("%s - %s - %s - %d"), ServerName, UserName, Password, (int)Operations);
292
293 if(!bLocal)
294 {
296
297
298 /* \\*IP or Computer Name*\*Share* */
299 _stprintf(RemoteResource, _T("\\\\%s\\IPC$"), ServerName);
300
301 nr.dwType = RESOURCETYPE_ANY;
302 nr.lpLocalName = NULL;
303 nr.lpProvider= NULL;
304 nr.lpRemoteName = RemoteResource;
305
306 /* open a connection to the server with difference user/pass. */
308
309 if(nStatus != NO_ERROR)
310 {
311 _tprintf(_T("Error:%d-%d\n"),(int)nStatus,GetLastError());
312 return 255;
313 }
314 }
315
316 /* Use GetVersionEx for anything that we are looking for locally */
317 if(bLocal)
318 {
321 {
322 _tprintf(_T("Failed to get local information\n"));
323 return 255;
324 }
325 }
326 else
327 {
328 nStatus = NetServerGetInfo(NULL,102,(LPBYTE *)&pBuf102);
329 if (nStatus != NERR_Success)
330 {
331 _tprintf(_T("Failed to connection to remote machine\n"));
332 return 255;
333 }
334
335 }
336
337 if(Operations & GETTYPE_VER)
338 {
339 ret = GetVersionNumber(bLocal, osvi, pBuf102);
340 }
341 else if(Operations & GETTYPE_MAJV)
342 {
343 ret = GetMajValue(TRUE, bLocal, osvi, pBuf102);
344 }
345 else if(Operations & GETTYPE_MINV)
346 {
347 ret = GetMajValue(FALSE, bLocal, osvi, pBuf102);
348 }
349 else if(Operations & GETTYPE_ROLE)
350 {
351 ret = GetSystemRole(bLocal, osvi, pBuf102);
352 }
353 else if(Operations & GETTYPE_SP)
354 {
355 ret = GetServicePack(bLocal, osvi, pBuf102, ServerName);
356 }
357 else if(Operations & GETTYPE_BUILD)
358 {
359 ret = GetBuildNumber(bLocal, osvi, pBuf102);
360 }
361 else if(Operations & GETTYPE_TYPE)
362 {
363 ret = GetType(bLocal, osvi, pBuf102);
364 }
365 else if(Operations & GETTYPE_HELP)
366 {
367 wprintf(L"GETTYPE [/ROLE | /SP | /VER | /MAJV | /MINV | /TYPE | /BUILD]");
368 ret = 0;
369 }
370 else if(!Operations && bLocal)
371 {
372 /* FIXME: what happens when no flags except remote machine, does it
373 it print this info for the remote server? */
374 TCHAR HostName[1024] = _T("");
375 TCHAR OSName[1024] = _T("");
376 TCHAR VersionInfo[1024] = _T("");
377 TCHAR Role[1024] = _T("");
378 TCHAR Components[1024] = _T("");
379 GetBasicInfo(osvi, HostName, OSName, VersionInfo, Role, Components);
380 _tprintf(_T("\nHostname: %s\nName: %s\nVersion:%s\n") ,HostName, OSName, VersionInfo);
381 _tprintf(_T("Role: %s\nComponent: %s\n"), Role, Components);
382 ret = 0;
383 }
384
385 /* Clean up some stuff that that was opened */
386 if(pBuf102)
387 NetApiBufferFree(pBuf102);
389 if(!bLocal)
390 {
391 WNetCancelConnection2(RemoteResource,0,TRUE);
392 }
393 return ret;
394}
static int argc
Definition: ServiceArgs.c:12
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
#define NO_ERROR
Definition: dderror.h:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: srvsvc.c:369
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
INT GetBuildNumber(BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
Definition: gettype.c:115
INT GetVersionNumber(BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
Definition: gettype.c:34
INT GetSystemRole(BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
Definition: gettype.c:73
INT GetServicePack(BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102, TCHAR *Server)
Definition: gettype.c:100
INT GetMajValue(BOOL Major, BOOL bLocal, LPOSVERSIONINFOEX osvi, LPSERVER_INFO_102 pBuf102)
Definition: gettype.c:52
VOID GetBasicInfo(LPOSVERSIONINFOEX osvi, TCHAR *HostName, TCHAR *OSName, TCHAR *Version, TCHAR *Role, TCHAR *Components)
Definition: gettype.c:163
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define _tcscpy
Definition: tchar.h:623
#define _tprintf
Definition: tchar.h:506
#define NERR_Success
Definition: lmerr.h:5
struct _SERVER_INFO_102 * LPSERVER_INFO_102
#define _stprintf
Definition: utility.h:124
ULONG nr
Definition: thread.c:7
#define argv
Definition: mplay32.c:18
#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)
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:80
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
@ Password
Definition: telnetd.h:65
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
OSVERSIONINFO osvi
Definition: ver.c:28
#define _T(x)
Definition: vfdio.h:22
int ret
#define wprintf(...)
Definition: whoami.c:18
#define GetType(This)
Definition: conio.h:54
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetVersionEx
Definition: winbase.h:3852
#define CONNECT_INTERACTIVE
Definition: winnetwk.h:90
#define CONNECT_COMMANDLINE
Definition: winnetwk.h:97
#define WNetCancelConnection2
Definition: winnetwk.h:607
#define WNetAddConnection2
Definition: winnetwk.h:604
#define RESOURCETYPE_ANY
Definition: winnetwk.h:63
OSVERSIONINFOEXA OSVERSIONINFOEX
Definition: rtltypes.h:290
LPOSVERSIONINFOEXA LPOSVERSIONINFOEX
Definition: rtltypes.h:292
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcsicmp
Definition: xmlstorage.h:205

◆ GetBasicInfo()

VOID GetBasicInfo ( LPOSVERSIONINFOEX  osvi,
TCHAR HostName,
TCHAR OSName,
TCHAR Version,
TCHAR Role,
TCHAR Components 
)

Definition at line 163 of file gettype.c.

164{
165 /* Host Name - COMPUTERNAME*/
166 DWORD bufCharCount = 1024;
167 GetComputerName(HostName, &bufCharCount);
168
169
170 /* OSName - Windows XP Home Editition */
171 if(osvi->dwMajorVersion == 4)
172 {
173 _tcscpy(OSName, _T("Microsoft Windows NT 4.0 "));
174 }
175 else if(osvi->dwMajorVersion == 5)
176 {
177 if(osvi->dwMinorVersion == 0)
178 {
179 _tcscpy(OSName, _T("Microsoft Windows 2000 "));
180 }
181 else if(osvi->dwMinorVersion == 1)
182 {
183 _tcscpy(OSName, _T("Microsoft Windows XP "));
184 }
185 else if(osvi->dwMinorVersion == 2)
186 {
187 _tcscpy(OSName, _T("Microsoft Windows Server 2003 "));
188 }
189 }
190 else if(osvi->dwMajorVersion == 6)
191 {
192 _tcscpy(OSName, _T("Microsoft Windows Vista "));
193 }
194 else
195 {
196 _tcscpy(OSName, _T("Microsoft Windows "));
197 }
198
199 if(osvi->wSuiteMask & VER_SUITE_BLADE)
200 _tcscat(OSName, _T("Web Edition"));
201 if(osvi->wSuiteMask & VER_SUITE_DATACENTER)
202 _tcscat(OSName, _T("Datacenter"));
203 if(osvi->wSuiteMask & VER_SUITE_ENTERPRISE)
204 _tcscat(OSName, _T("Enterprise"));
205 if(osvi->wSuiteMask & VER_SUITE_EMBEDDEDNT)
206 _tcscat(OSName, _T("Embedded"));
207 if(osvi->wSuiteMask & VER_SUITE_PERSONAL)
208 _tcscat(OSName, _T("Home Edition"));
210 _tcscat(OSName, _T("Small Bussiness Edition"));
211
212 /* Version - 5.1 Build 2600 Serivce Pack 2 */
213 _stprintf(Version, _T("%d.%d Build %d %s"),(int)osvi->dwMajorVersion,(int)osvi->dwMinorVersion,(int)osvi->dwBuildNumber, osvi->szCSDVersion);
214
215 /* Role - Workgroup / Server / Domain Controller */
216 if(osvi->wProductType == VER_NT_DOMAIN_CONTROLLER)
217 _tcscpy(Role, _T("Domain Controller"));
218 else if(osvi->wProductType == VER_NT_SERVER)
219 _tcscpy(Role, _T("Server"));
220 else if(osvi->wProductType == VER_NT_WORKSTATION)
221 _tcscpy(Role, _T("Workgroup"));
222
223 /* Components - FIXME: what is something that might be installed? */
224 _tcscat(Components, _T("Not Installed"));
225
226}
#define _tcscat
Definition: tchar.h:622
#define VER_SUITE_SMALLBUSINESS_RESTRICTED
#define VER_SUITE_ENTERPRISE
#define VER_SUITE_SMALLBUSINESS
#define VER_SUITE_DATACENTER
#define VER_SUITE_PERSONAL
#define VER_SUITE_BLADE
#define VER_SUITE_EMBEDDEDNT
CHAR szCSDVersion[128]
Definition: rtltypes.h:242
ULONG dwMajorVersion
Definition: rtltypes.h:238
ULONG dwBuildNumber
Definition: rtltypes.h:240
ULONG dwMinorVersion
Definition: rtltypes.h:239
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
#define GetComputerName
Definition: winbase.h:3800
#define VER_NT_WORKSTATION
#define VER_NT_SERVER
#define VER_NT_DOMAIN_CONTROLLER

Referenced by _tmain().

◆ GetBuildNumber()

INT GetBuildNumber ( BOOL  bLocal,
LPOSVERSIONINFOEX  osvi,
LPSERVER_INFO_102  pBuf102 
)

Definition at line 115 of file gettype.c.

116{
117 INT BuildNum = 255;
118 if(!bLocal)
119 {
120 /* FIXME: Use Registry to get value */
121 }
122 else
123 {
124 BuildNum = osvi->dwBuildNumber;
125 }
126 return BuildNum;
127}

Referenced by _tmain().

◆ GetMajValue()

INT GetMajValue ( BOOL  Major,
BOOL  bLocal,
LPOSVERSIONINFOEX  osvi,
LPSERVER_INFO_102  pBuf102 
)

Definition at line 52 of file gettype.c.

53{
54 INT VersionNumber = 255;
55 if(pBuf102 != NULL && !bLocal)
56 {
57 if(Major)
58 VersionNumber = pBuf102->sv102_version_major * 1000;
59 else
60 VersionNumber = pBuf102->sv102_version_minor * 100;
61 }
62 else
63 {
64 if(Major)
65 VersionNumber = osvi->dwMajorVersion * 1000;
66 else
67 VersionNumber = osvi->dwMinorVersion * 100;
68 }
69 return VersionNumber;
70}
DWORD sv102_version_major
Definition: lmserver.h:28
DWORD sv102_version_minor
Definition: lmserver.h:29

Referenced by _tmain().

◆ GetServicePack()

INT GetServicePack ( BOOL  bLocal,
LPOSVERSIONINFOEX  osvi,
LPSERVER_INFO_102  pBuf102,
TCHAR Server 
)

Definition at line 100 of file gettype.c.

101{
102 INT SPNumber = 255;
103 if(!bLocal)
104 {
105 /* FIXME: Use Registry to get value */
106 }
107 else
108 {
109 SPNumber = osvi->wServicePackMajor;
110 }
111 return SPNumber;
112}

Referenced by _tmain().

◆ GetSystemRole()

INT GetSystemRole ( BOOL  bLocal,
LPOSVERSIONINFOEX  osvi,
LPSERVER_INFO_102  pBuf102 
)

Definition at line 73 of file gettype.c.

74{
75
76 if(pBuf102 != NULL && !bLocal)
77 {
78 if ((pBuf102->sv102_type & SV_TYPE_DOMAIN_CTRL) ||
80 return 1;
81 else if(pBuf102->sv102_type & SV_TYPE_SERVER_NT)
82 return 2;
83 else
84 return 3;
85 }
86 else
87 {
88 if(osvi->wProductType == VER_NT_DOMAIN_CONTROLLER)
89 return 1;
90 else if(osvi->wProductType == VER_NT_SERVER)
91 return 2;
92 else if(osvi->wProductType == VER_NT_WORKSTATION)
93 return 3;
94 }
95 return 255;
96
97}
#define SV_TYPE_SERVER_NT
Definition: lmserver.h:443
#define SV_TYPE_DOMAIN_BAKCTRL
Definition: lmserver.h:431
#define SV_TYPE_DOMAIN_CTRL
Definition: lmserver.h:430
DWORD sv102_type
Definition: lmserver.h:30

Referenced by _tmain().

◆ GetType()

INT GetType ( BOOL  bLocal,
LPOSVERSIONINFOEX  osvi,
LPSERVER_INFO_102  pBuf102 
)

Definition at line 129 of file gettype.c.

130{
131 if(bLocal)
132 {
133 if(osvi->dwMajorVersion == 5)
134 {
135 if(osvi->dwMinorVersion == 1)
136 {
137 if(osvi->wSuiteMask & VER_SUITE_PERSONAL)
138 return 1;
139 else
140 return 2;
141 }
142 else if(osvi->dwMinorVersion == 2)
143 {
144 if(osvi->wSuiteMask & VER_SUITE_BLADE)
145 return 6;
146 else if(osvi->wSuiteMask & VER_SUITE_DATACENTER)
147 return 5;
148 else if(osvi->wSuiteMask & VER_SUITE_ENTERPRISE)
149 return 4;
150 else
151 return 3;
152 }
153 }
154 }
155 else
156 {
157 /* FIXME: Get this value from registry */
158 }
159 return 255;
160}

◆ GetVersionNumber()

INT GetVersionNumber ( BOOL  bLocal,
LPOSVERSIONINFOEX  osvi,
LPSERVER_INFO_102  pBuf102 
)

Definition at line 34 of file gettype.c.

35{
36 INT VersionNumber = 255;
37 if(pBuf102 != NULL && !bLocal)
38 {
39 VersionNumber = pBuf102->sv102_version_major * 1000;
40 VersionNumber += (pBuf102->sv102_version_minor * 100);
41 }
42 else if(bLocal)
43 {
44 VersionNumber = osvi->dwMajorVersion * 1000;
45 VersionNumber += (osvi->dwMinorVersion * 100);
46 }
47
48 return VersionNumber;
49}

Referenced by _tmain().