xref: /reactos/base/shell/cmd/ver.c (revision ac0bcf4a)
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 
28 OSVERSIONINFO osvi;
29 TCHAR szOSName[50] = _T("");
30 
31 
32 VOID InitOSVersion(VOID)
33 {
34     LONG lResult;
35     HKEY hKey;
36 
37     /* Get version information */
38     ZeroMemory(&osvi, sizeof(osvi));
39     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
40     GetVersionEx(&osvi);
41 
42     /* Build OS version string */
43 
44     /* Open registry key */
45     lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
46                            _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
47                            0,
48                            KEY_QUERY_VALUE,
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,
60                                   (LPBYTE)szOSName,
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         {
88             case VER_PLATFORM_WIN32_WINDOWS:
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 
104             case VER_PLATFORM_WIN32_NT:
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 */
114 VOID PrintOSVersion(VOID)
115 {
116     ConOutResPrintf(STRING_VERSION_RUNVER, szOSName,
117                     osvi.dwMajorVersion, osvi.dwMinorVersion,
118                     osvi.dwBuildNumber, osvi.szCSDVersion);
119 }
120 
121 #ifdef INCLUDE_CMD_VER
122 
123 /*
124  * display shell version info internal command.
125  */
126 INT cmd_ver (LPTSTR param)
127 {
128     INT i;
129 
130     nErrorLevel = 0;
131 
132     if (_tcsstr(param, _T("/?")) != NULL)
133     {
134         ConOutResPaging(TRUE,STRING_VERSION_HELP1);
135         return 0;
136     }
137 
138     ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_VERSION_STR), _T(KERNEL_VERSION_BUILD_STR));
139     ConOutChar(_T('\n'));
140     ConOutResPuts(STRING_VERSION_RUNNING_ON);
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         ConOutResPrintf(STRING_CMD_COPYRIGHT, _T(COPYRIGHT_YEAR));
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 */
170                 ConOutResPuts(STRING_VERSION_HELP3);
171             }
172             else if (_totupper(param[i]) == _T('R'))
173             {
174                 /* Redistribution notice */
175                 ConOutResPuts(STRING_VERSION_HELP4);
176             }
177             else if (_totupper(param[i]) == _T('C'))
178             {
179                 /* Developer listing */
180                 ConOutResPuts(STRING_VERSION_HELP6);
181                 ConOutResPuts(STRING_FREEDOS_DEV);
182                 ConOutResPuts(STRING_VERSION_HELP7);
183                 ConOutResPuts(STRING_REACTOS_DEV);
184             }
185             else
186             {
187                 error_invalid_switch(_totupper(param[i]));
188                 return 1;
189             }
190         }
191 
192         /* Bug report notice */
193         ConOutResPuts(STRING_VERSION_HELP5);
194     }
195 
196     ConOutChar(_T('\n'));
197 
198     return 0;
199 }
200 
201 #endif
202