2 * ReactOS Win32 Applications
3 * Copyright (C) 2005 ReactOS Team
5 * COPYRIGHT: See COPYING in the top level directory
6 * PROJECT: ReactOS arp utility
7 * FILE: apps/utils/gettype/gettype.c
9 * PROGRAMMERS: Brandon Turner (turnerb7@msu.edu)
13 * FIXME: gettype only supports local computer.
34 GetVersionNumber(BOOL bLocal
, LPOSVERSIONINFOEX osvi
, LPSERVER_INFO_102 pBuf102
)
36 INT VersionNumber
= 255;
37 if(pBuf102
!= NULL
&& !bLocal
)
39 VersionNumber
= pBuf102
->sv102_version_major
* 1000;
40 VersionNumber
+= (pBuf102
->sv102_version_minor
* 100);
44 VersionNumber
= osvi
->dwMajorVersion
* 1000;
45 VersionNumber
+= (osvi
->dwMinorVersion
* 100);
52 GetMajValue(BOOL Major
, BOOL bLocal
, LPOSVERSIONINFOEX osvi
, LPSERVER_INFO_102 pBuf102
)
54 INT VersionNumber
= 255;
55 if(pBuf102
!= NULL
&& !bLocal
)
58 VersionNumber
= pBuf102
->sv102_version_major
* 1000;
60 VersionNumber
= pBuf102
->sv102_version_minor
* 100;
65 VersionNumber
= osvi
->dwMajorVersion
* 1000;
67 VersionNumber
= osvi
->dwMinorVersion
* 100;
73 GetSystemRole(BOOL bLocal
, LPOSVERSIONINFOEX osvi
, LPSERVER_INFO_102 pBuf102
)
76 if(pBuf102
!= NULL
&& !bLocal
)
78 if ((pBuf102
->sv102_type
& SV_TYPE_DOMAIN_CTRL
) ||
79 (pBuf102
->sv102_type
& SV_TYPE_DOMAIN_BAKCTRL
))
81 else if(pBuf102
->sv102_type
& SV_TYPE_SERVER_NT
)
88 if(osvi
->wProductType
== VER_NT_DOMAIN_CONTROLLER
)
90 else if(osvi
->wProductType
== VER_NT_SERVER
)
92 else if(osvi
->wProductType
== VER_NT_WORKSTATION
)
100 GetServicePack(BOOL bLocal
, LPOSVERSIONINFOEX osvi
, LPSERVER_INFO_102 pBuf102
, TCHAR
* Server
)
105 /* FIXME: Use Registry to get value */
109 SPNumber
= osvi
->wServicePackMajor
;
115 GetBuildNumber(BOOL bLocal
, LPOSVERSIONINFOEX osvi
, LPSERVER_INFO_102 pBuf102
)
120 /* FIXME: Use Registry to get value */
124 BuildNum
= osvi
->dwBuildNumber
;
129 INT
GetType(BOOL bLocal
, LPOSVERSIONINFOEX osvi
, LPSERVER_INFO_102 pBuf102
)
133 if(osvi
->dwMajorVersion
== 5)
135 if(osvi
->dwMinorVersion
== 1)
137 if(osvi
->wSuiteMask
& VER_SUITE_PERSONAL
)
142 else if(osvi
->dwMinorVersion
== 2)
144 if(osvi
->wSuiteMask
& VER_SUITE_BLADE
)
146 else if(osvi
->wSuiteMask
& VER_SUITE_DATACENTER
)
148 else if(osvi
->wSuiteMask
& VER_SUITE_ENTERPRISE
)
157 /* FIXME: Get this value from registry */
163 GetBasicInfo(LPOSVERSIONINFOEX osvi
, TCHAR
* HostName
, TCHAR
* OSName
, TCHAR
* Version
, TCHAR
* Role
, TCHAR
* Components
)
165 /* Host Name - COMPUTERNAME*/
166 DWORD bufCharCount
= 1024;
167 GetComputerName(HostName
, &bufCharCount
);
170 /* OSName - Windows XP Home Editition */
171 if(osvi
->dwMajorVersion
== 4)
173 _tcscpy(OSName
, _T("Microsoft Windows NT 4.0 "));
175 else if(osvi
->dwMajorVersion
== 5)
177 if(osvi
->dwMajorVersion
== 0)
179 _tcscpy(OSName
, _T("Microsoft Windows 2000 "));
181 else if(osvi
->dwMinorVersion
== 1)
183 _tcscpy(OSName
, _T("Microsoft Windows XP "));
185 else if(osvi
->dwMinorVersion
== 2)
187 _tcscpy(OSName
, _T("Microsoft Windows Server 2003 "));
190 else if(osvi
->dwMajorVersion
== 6)
192 _tcscpy(OSName
, _T("Microsoft Windows Vista "));
196 _tcscpy(OSName
, _T("Microsoft Windows "));
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"));
209 if(osvi
->wSuiteMask
& VER_SUITE_SMALLBUSINESS_RESTRICTED
&& osvi
->wSuiteMask
& VER_SUITE_SMALLBUSINESS
)
210 _tcscat(OSName
, _T("Small Bussiness Edition"));
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
);
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"));
223 /* Components - FIXME: what is something that might be installed? */
224 _tcscat(Components
, _T("Not Installed"));
231 DWORD Operations
= 0;
235 /* True if the target is local host */
238 TCHAR ServerName
[32];
239 TCHAR RemoteResource
[32];
240 TCHAR UserName
[32] = _T("");
241 TCHAR Password
[32] = _T("");
242 LPOSVERSIONINFOEX osvi
= NULL
;
243 LPSERVER_INFO_102 pBuf102
= NULL
;
245 osvi
= (LPOSVERSIONINFOEX
)malloc(sizeof(LPOSVERSIONINFOEX
));
246 pBuf102
= (LPSERVER_INFO_102
)malloc(sizeof(LPSERVER_INFO_102
));
248 /* Get the command line correctly since it is unicode */
249 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
255 for (i
= 1; i
< argc
; i
++)
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
)
275 _tcscpy(ServerName
,argv
[++i
]);
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
)
281 _tcscpy(Password
,argv
[++i
]);
284 wprintf(L
"Error in paramters, please see usage\n");
290 /* Some debug info */
291 //_tprintf(_T("%s - %s - %s - %d"), ServerName, UserName, Password, (int)Operations);
298 /* \\*IP or Computer Name*\*Share* */
299 _stprintf(RemoteResource
, _T("\\\\%s\\IPC$"), ServerName
);
301 nr
.dwType
= RESOURCETYPE_ANY
;
302 nr
.lpLocalName
= NULL
;
304 nr
.lpRemoteName
= RemoteResource
;
306 /* open a connection to the server with difference user/pass. */
307 nStatus
= WNetAddConnection2(&nr
, UserName
[0]?UserName
:NULL
,Password
[0]?Password
:NULL
, CONNECT_INTERACTIVE
| CONNECT_COMMANDLINE
);
309 if(nStatus
!= NO_ERROR
)
311 _tprintf(_T("Error:%d-%d\n"),(int)nStatus
,GetLastError());
316 /* Use GetVersionEx for anything that we are looking for locally */
319 osvi
->dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
320 if(!GetVersionEx((LPOSVERSIONINFO
)osvi
))
322 _tprintf(_T("Failed to get local information\n"));
328 nStatus
= NetServerGetInfo(NULL
,102,(LPBYTE
*)&pBuf102
);
329 if (nStatus
!= NERR_Success
)
331 _tprintf(_T("Failed to connection to remote machine\n"));
337 if(Operations
& GETTYPE_VER
)
339 ret
= GetVersionNumber(bLocal
, osvi
, pBuf102
);
341 else if(Operations
& GETTYPE_MAJV
)
343 ret
= GetMajValue(TRUE
, bLocal
, osvi
, pBuf102
);
345 else if(Operations
& GETTYPE_MINV
)
347 ret
= GetMajValue(FALSE
, bLocal
, osvi
, pBuf102
);
349 else if(Operations
& GETTYPE_ROLE
)
351 ret
= GetSystemRole(bLocal
, osvi
, pBuf102
);
353 else if(Operations
& GETTYPE_SP
)
355 ret
= GetServicePack(bLocal
, osvi
, pBuf102
, ServerName
);
357 else if(Operations
& GETTYPE_BUILD
)
359 ret
= GetBuildNumber(bLocal
, osvi
, pBuf102
);
361 else if(Operations
& GETTYPE_TYPE
)
363 ret
= GetType(bLocal
, osvi
, pBuf102
);
365 else if(Operations
& GETTYPE_HELP
)
367 wprintf(L
"GETTYPE [/ROLE | /SP | /VER | /MAJV | /MINV | /TYPE | /BUILD]");
370 else if(!Operations
&& bLocal
)
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
);
385 /* Clean up some stuff that that was opened */
387 NetApiBufferFree(pBuf102
);
391 WNetCancelConnection2(RemoteResource
,0,TRUE
);