Visual Studio 2005: OSVersion restriction

Hello,

I have a code for a GUI which includes the script below.
All runs as it should but I am stuck with implementing another "switch" into it.

What I actually need is that while the code does anyway run, it will directly check for a specific Windows version which I can freely define and it then will deny the run of the application with a specific print out.

This is what I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#define BUFSIZE 4096
BOOL SystemTweaks::getOSVersionString(std::string& rstrOSVersion, unsigned int *puiPlatformID, unsigned int *puiMajorVersion, unsigned int *puiMinorVersion) {
	OSVERSIONINFOEX osvi;
	BOOL bOsVersionInfoEx;

	// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
	// If that fails, try using the OSVERSIONINFO structure.
	rstrOSVersion = "";
	ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

	if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
	{
		osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
		if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
			return FALSE;
	}

	if (puiMajorVersion && puiMinorVersion && puiPlatformID) {
		*puiPlatformID = osvi.dwPlatformId;
		*puiMajorVersion = osvi.dwMajorVersion;
		*puiMinorVersion = osvi.dwMinorVersion;
	}

	switch (osvi.dwPlatformId)
	{
		// Test for the Windows NT product family.
	case VER_PLATFORM_WIN32_NT:

		// Test for the specific product.
		if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)
			rstrOSVersion += "Windows Vista ";

		if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1)
			rstrOSVersion += "Windows 7 ";

		if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
			rstrOSVersion += "Windows Server 2003 ";

		if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
			rstrOSVersion += "Windows XP ";

		if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
			rstrOSVersion += "Microsoft Windows 2000 ";

		if ( osvi.dwMajorVersion <= 4 )
			rstrOSVersion += "Microsoft Windows NT ";

		// Test for specific product on Windows NT 4.0 SP6 and later.
		if( bOsVersionInfoEx )
		{
			// Test for the workstation type.
			if ( osvi.wProductType == VER_NT_WORKSTATION )
			{
				if( osvi.dwMajorVersion == 4 )
					rstrOSVersion += "Workstation 4.0 ";
				else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
					rstrOSVersion +=  "Home Edition ";
				else {
					switch ( osvi.wProductType){
	case 0x00000001: // ultimate 
		{
			if (rstrOSVersion.find("Windows XP", 0) == 0) {
				rstrOSVersion +=  "Professional ";
			} else {
				rstrOSVersion +=  "Ultimate ";
			}
		}
		break;
	case 0x00000030: // professional
		rstrOSVersion +=  "Professional ";
		break;
					}					
				}
			}

			// Test for the server type.
			else if ( osvi.wProductType == VER_NT_SERVER || 
				osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
			{
				if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
				{
					if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
						rstrOSVersion += "Datacenter Edition ";
					else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
						rstrOSVersion += "Enterprise Edition ";
					else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
						rstrOSVersion +=  "Web Edition ";
					else
						rstrOSVersion +=  "Standard Edition ";
				}
				else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
				{
					if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
						rstrOSVersion += "Datacenter Server ";
					else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
						rstrOSVersion += "Advanced Server ";
					else 
						rstrOSVersion += "Server ";
				}
				else  // Windows NT 4.0 
				{
					if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
						rstrOSVersion += "Server 4.0, Enterprise Edition ";
					else 
						rstrOSVersion += "Server 4.0 ";
				}
			}
		}
		// Test for specific product on Windows NT 4.0 SP5 and earlier
		else  
		{
			HKEY hKey;
			char szProductType[BUFSIZE];
			DWORD dwBufLen=BUFSIZE;
			LONG lRet;

			lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
				"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
				0, KEY_QUERY_VALUE, &hKey );
			if( lRet != ERROR_SUCCESS )
				return FALSE;

			lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
				(LPBYTE) szProductType, &dwBufLen);
			if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
				return FALSE;

			RegCloseKey( hKey );

			if ( lstrcmpi( "WINNT", szProductType) == 0 )
				rstrOSVersion += "Workstation ";
			if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
				rstrOSVersion += "Server ";
			if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
				rstrOSVersion += "Advanced Server ";
			char acRevision[1000];
			sprintf_s(acRevision, "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion );
			rstrOSVersion += acRevision;
		}

		// Display service pack (if any) and build number.

		if( osvi.dwMajorVersion == 4 && 
			lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )
		{ 
			HKEY hKey;
			LONG lRet;

			// Test for SP6 versus SP6a.
			lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
				"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
				0, KEY_QUERY_VALUE, &hKey );
			if( lRet == ERROR_SUCCESS ) {
				char acBuildNum[1000];
				sprintf_s(acBuildNum, "Service Pack 6a (Build %d) ", osvi.dwBuildNumber & 0xFFFF );         
				rstrOSVersion += acBuildNum;
			} else // Windows NT 4.0 prior to SP6a
			{
				char acBuildNum[1000];
				sprintf_s(acBuildNum, "%s - Build %d\n",
					osvi.szCSDVersion,
					osvi.dwBuildNumber & 0xFFFF);
				rstrOSVersion += acBuildNum;
			}

			RegCloseKey( hKey );
		}
		else // not Windows NT 4.0 
		{
			char acBuildNum[1000];
			sprintf_s(acBuildNum, "%s - Build %d\n",
				osvi.szCSDVersion,
				osvi.dwBuildNumber & 0xFFFF);
			rstrOSVersion += acBuildNum;
		}

		break;

		// Test for the Windows Me/98/95.
	case VER_PLATFORM_WIN32_WINDOWS:

		if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
		{
			rstrOSVersion += "Windows 95 ";
			if (osvi.szCSDVersion[1]=='C' || osvi.szCSDVersion[1]=='B')
				rstrOSVersion +=  "OSR2 ";
		} 

		if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
		{
			rstrOSVersion += "Windows 98 ";
			if ( osvi.szCSDVersion[1] == 'A' )
				rstrOSVersion += "SE ";
		} 

		if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
		{
			rstrOSVersion += "Windows Millennium Edition\n";
		} 
		break;

	case VER_PLATFORM_WIN32s:

		rstrOSVersion += "Win32s";
		break;
	}

	return TRUE; 
}



Any help is highly appreciated thanks!
Topic archived. No new replies allowed.