ReactOS  0.4.14-dev-608-gd495a4f
ver.c
Go to the documentation of this file.
1 /*
2  * VER.C - ver internal command.
3  *
4  *
5  * History:
6  *
7  * 06/30/98 (Rob Lake)
8  * rewrote ver command to accept switches, now ver alone prints
9  * copyright notice only.
10  *
11  * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
12  * added config.h include
13  *
14  * 30-Jul-1998 (John P Price <linux-guru@gcfl.net>)
15  * added text about where to send bug reports and get updates.
16  *
17  * 20-Jan-1999 (Eric Kohl)
18  * Unicode and redirection safe!
19  *
20  * 26-Feb-1999 (Eric Kohl)
21  * New version info and some output changes.
22  */
23 
24 #include "precomp.h"
25 #include <reactos/buildno.h>
26 #include <reactos/version.h>
27 
29 TCHAR szOSName[50] = _T("");
30 
31 
33 {
34  LONG lResult;
35  HKEY hKey;
36 
37  /* Get version information */
38  ZeroMemory(&osvi, sizeof(osvi));
41 
42  /* Build OS version string */
43 
44  /* Open registry key */
46  _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
47  0,
49  &hKey);
50  if (lResult == ERROR_SUCCESS)
51  {
52  DWORD dwSize, dwType;
53 
54  /* Retrieve the ProductName value */
55  dwSize = sizeof(szOSName);
56  lResult = RegQueryValueEx(hKey,
57  _T("ProductName"),
58  NULL,
59  &dwType,
61  &dwSize);
62 
63  /* If we have failed or the data type is unsupported... */
64  if (lResult != ERROR_SUCCESS || dwType != REG_SZ)
65  {
66  /* ... reserve size for one NULL character only! */
67  dwSize = sizeof(TCHAR);
68 
69  /* Set an error code (anything != ERROR_SUCCESS) */
70  lResult = ERROR_INVALID_PARAMETER;
71  }
72 
73  /* NULL-terminate the string */
74  szOSName[(dwSize / sizeof(TCHAR)) - 1] = _T('\0');
75 
76  /* Close the key */
77  RegCloseKey(hKey);
78  }
79 
80  /*
81  * If the registry key somehow doesn't exist or cannot be loaded, then
82  * determine at least whether the version of Windows is either 9x or NT.
83  */
84  if (lResult != ERROR_SUCCESS)
85  {
86  switch (osvi.dwPlatformId)
87  {
89  {
90  if (osvi.dwMajorVersion == 4)
91  {
92  if (osvi.dwMinorVersion == 0)
93  _tcscpy(szOSName, _T("Windows 95"));
94  else if (osvi.dwMinorVersion == 1)
95  _tcscpy(szOSName, _T("Windows 98"));
96  else if (osvi.dwMinorVersion == 9)
97  _tcscpy(szOSName, _T("Windows ME"));
98  else
99  _tcscpy(szOSName, _T("Windows 9x"));
100  }
101  break;
102  }
103 
105  {
106  _tcscpy(szOSName, _T("Windows NT"));
107  break;
108  }
109  }
110  }
111 }
112 
113 /* Print the current OS version, suitable for VER command and PROMPT $V format */
115 {
119 }
120 
121 #ifdef INCLUDE_CMD_VER
122 
123 /*
124  * display shell version info internal command.
125  */
127 {
128  INT i;
129 
130  nErrorLevel = 0;
131 
132  if (_tcsstr(param, _T("/?")) != NULL)
133  {
135  return 0;
136  }
137 
138  ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_VERSION_STR), _T(KERNEL_VERSION_BUILD_STR));
139  ConOutChar(_T('\n'));
141  PrintOSVersion();
142 
143  /* Basic copyright notice */
144  if (param[0] != _T('\0'))
145  {
146  ConOutPuts(_T("\n\n"));
147  ConOutPuts(_T("Copyright (C) 1994-1998 Tim Norman and others.\n"));
148  ConOutPuts(_T("Copyright (C) 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team\n"));
149 
150  for (i = 0; param[i]; i++)
151  {
152  /* Skip spaces */
153  if (param[i] == _T(' '))
154  continue;
155 
156  if (param[i] == _T('/'))
157  {
158  /* Is this a lone '/' ? */
159  if (param[i + 1] == 0)
160  {
161  error_invalid_switch(_T(' '));
162  return 1;
163  }
164  continue;
165  }
166 
167  if (_totupper(param[i]) == _T('W'))
168  {
169  /* Warranty notice */
171  }
172  else if (_totupper(param[i]) == _T('R'))
173  {
174  /* Redistribution notice */
176  }
177  else if (_totupper(param[i]) == _T('C'))
178  {
179  /* Developer listing */
184  }
185  else
186  {
188  return 1;
189  }
190  }
191 
192  /* Bug report notice */
194  }
195 
196  ConOutChar(_T('\n'));
197 
198  return 0;
199 }
200 
201 #endif
#define STRING_CMD_SHELLINFO
Definition: resource.h:90
#define RegQueryValueEx
Definition: winreg.h:524
INT nErrorLevel
Definition: cmd.c:157
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
VOID InitOSVersion(VOID)
Definition: ver.c:32
#define VER_PLATFORM_WIN32_NT
Definition: rtltypes.h:236
#define TRUE
Definition: types.h:120
ULONG dwMajorVersion
Definition: rtltypes.h:234
#define STRING_VERSION_HELP4
Definition: resource.h:193
#define STRING_REACTOS_DEV
Definition: resource.h:244
#define ERROR_SUCCESS
Definition: deptool.c:10
OSVERSIONINFO osvi
Definition: ver.c:28
#define STRING_VERSION_HELP3
Definition: resource.h:192
VOID ConOutChar(TCHAR c)
Definition: console.c:123
#define STRING_VERSION_HELP5
Definition: resource.h:194
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ZeroMemory
Definition: winbase.h:1642
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define _totupper
Definition: tchar.h:1509
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
TCHAR szOSName[50]
Definition: ver.c:29
OSVERSIONINFOA OSVERSIONINFO
Definition: rtltypes.h:289
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:233
ULONG dwBuildNumber
Definition: rtltypes.h:236
#define _tcsstr
Definition: xmlstorage.h:199
#define STRING_VERSION_HELP1
Definition: resource.h:190
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define STRING_VERSION_HELP7
Definition: resource.h:196
GLfloat param
Definition: glext.h:5796
#define STRING_FREEDOS_DEV
Definition: resource.h:243
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID error_invalid_switch(TCHAR)
Definition: error.c:70
VOID PrintOSVersion(VOID)
Definition: ver.c:114
ULONG dwMinorVersion
Definition: rtltypes.h:235
#define RegOpenKeyEx
Definition: winreg.h:520
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
ULONG dwPlatformId
Definition: rtltypes.h:237
#define GetVersionEx
Definition: winbase.h:3686
#define STRING_VERSION_RUNNING_ON
Definition: resource.h:197
#define VER_PLATFORM_WIN32_WINDOWS
Definition: rtltypes.h:235
#define ConOutResPuts(uID)
Definition: console.h:36
CHAR szCSDVersion[128]
Definition: rtltypes.h:238
#define STRING_VERSION_HELP6
Definition: resource.h:195
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
INT cmd_ver(LPTSTR param)
Definition: ver.c:126
VOID ConOutPuts(LPTSTR szText)
Definition: tee.c:27
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22
#define STRING_VERSION_RUNVER
Definition: resource.h:198