Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

dotNetInstaller - Setup Bootstrapper for .NET Application

, 4 Jan 2004
With this tool the developer can define the application prerequisites and install the correct version of these components in the correct order based on the user operating system type and language, allow the user to download these components from the web or install these components directly.
dotnetinstaller_source.zip
dotNetInstaller_source
dotNetInstaller
dotNetInstaller.vcproj.vspscc
dotNetInstaller.vssscc
mssccprj.scc
res
banner.bmp
dotNetInstaller.ico
dotNetInstaller.manifest
Thumbs.db
vssver.scc
Tools
vssver.scc
vssver.scc
InstallerEditor
App.ico
banner.bmp
bin
Release
InstallerEditor.exe
SourceLibrary.dll
vssver.scc
InstallerEditor.csproj.user
InstallerEditor.csproj.vspscc
InstallerEditor.suo
InstallerEditor.vssscc
mssccprj.scc
References
SourceLibrary.dll
vssver.scc
Thumbs.db
vssver.scc
Sample
banner.bmp
dotNetInstaller.exe
SupportFiles
DataAccess
Jet
Jet40Sp7
Win2000_English
Win2000_Italiano
Win9x_NT
WinME
WinXp_English
WinXp_Italiano
MDAC2.7Sp1Refresh
Win_98_ME_NT_2000
dotNet
v1.1
English
Italiano
InternetExplorer
IE60SP1_English
IE60SP1_Italiano
ServicePack
2000_SP4_English
2000_SP4_Italiano
NT4_SP6a_English
NT4_SP6a_Italiano
Win98_Y2k_Update_English
Win98_Y2k_Update_Italiano
#pragma once

#include <windows.h>
#include <stdio.h>
#include "split.h"
#include "File.h"

namespace DVLib
{
	enum OperatingSystem
	{
		winNotValid = 0,

		win95 = 5,
		win95osr2 = 10,

		win98 = 15,
		win98se = 20,

		winME = 25,

		winNT4 = 30,
		winNT4sp6 = 35,
		winNT4sp6a = 40,

		win2000 = 45,
		win2000sp1 = 50,
		win2000sp2 = 55,
		win2000sp3 = 60,
		win2000sp4 = 65, //or Later

		winXP = 75,
		winXPsp1 = 80,  //or Later

		winServer2003 = 90,

		winLater = 100
	};

	inline OperatingSystem GetOsVersion()
	{
		OperatingSystem l_Os;

		OSVERSIONINFOEX osvi;
		BOOL bOsVersionInfoEx;

		// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
		// If that fails, try using the OSVERSIONINFO structure.
		ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
		osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
		if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
		{
			osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
			if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
				return winNotValid;
		}

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

				// NT Version
				if ( (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion > 2) || 
					osvi.dwMajorVersion > 5)
				{
					l_Os = winLater; //versione pi� nuova
				}
				else if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
				{
					l_Os = winServer2003;
				}
				else if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
				{
					l_Os = winXP;

					if (osvi.wServicePackMajor >= 1)
						l_Os = winXPsp1;
				}
				else if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
				{
					l_Os = win2000;

					if (osvi.wServicePackMajor >= 4)
						l_Os = win2000sp4;
					else if (osvi.wServicePackMajor == 3)
						l_Os = win2000sp3;
					else if (osvi.wServicePackMajor == 2)
						l_Os = win2000sp2;
					else if (osvi.wServicePackMajor == 1)
						l_Os = win2000sp1;

				}
				else if ( osvi.dwMajorVersion = 4 )
				{
					l_Os = winNT4;
					//check if Sp6a
					if(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 ) //sp6a
							l_Os = winNT4sp6a;
						else // Windows NT 4.0 prior to SP6a
							l_Os = winNT4sp6;

						RegCloseKey( hKey );
					}
				}
				else
				{
					l_Os = winNotValid;
				}

			break;

			// Test for the Windows 95 product family.
			case VER_PLATFORM_WIN32_WINDOWS:

				if ( (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion > 90) ||
					osvi.dwMajorVersion > 4) 
				{
					l_Os = winLater;
				}
				else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
				{
					l_Os = winME;
				}
				else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
				{
					l_Os = win98;
					//test windows 98 se
					if ( osvi.szCSDVersion[1] == 'A' )
						l_Os = win98se;
				}
				else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
				{
					l_Os = win95;
					//test Win95 osr2
					if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
						l_Os = win95osr2;
				} 
				else
				{
					l_Os = winNotValid;
				}
			break;

		case VER_PLATFORM_WIN32s:

			l_Os = winNotValid;

			break;
	}

	return l_Os; 
	}

	inline CString GetOsVersionString()
	{
		OperatingSystem l_os = GetOsVersion();

		switch(l_os)
		{
		case winNotValid:
			return "Not Valid Operating System";
		case win95:
			return "Windows 95";
		case win95osr2:
			return "Windows 95 osr2";
		case win98:
			return "Windows 98";
		case win98se:
			return "Windows 98 Second Edition";
		case winME:
			return "Windows ME";
		case winNT4:
			return "Windows NT 4";
		case winNT4sp6:
			return "Windows NT 4 Sp6";
		case winNT4sp6a:
			return "Windows NT 4 Sp6a";
		case win2000:
			return "Windows 2000";
		case win2000sp1:
			return "Windows 2000 Sp1";
		case win2000sp2:
			return "Windows 2000 Sp2";
		case win2000sp3:
			return "Windows 2000 Sp3";
		case win2000sp4:
			return "Windows 2000 Sp4";
		case winXP:
			return "Windows XP";
		case winXPsp1:
			return "Windows XP Sp1";
		case winServer2003:
			return "Windows Server 2003";
		case winLater:
			return "Unknown Windows version";
		default:
			return "Error";
		}
	}

	// This function returns true if the current operating system is between the minor and major bounds (estremi esclusi)
	// p_CurrentOs = current operating sistem
	// p_GreaterThan = minor bound to check (if "" no check performed)
	// p_SmallerThan = major bound to check (if "" no check performed)
	// example: 
	//  IsInRangedOs(50, "49", "59") == true
	//  IsInRangedOs(50, "50", "59") == false
	//  IsInRangedOs(50, "49", "50") == false
	//  IsInRangedOs(50, "39", "49") == false
	//  IsInRangedOs(50, "49", "") == true
	//  IsInRangedOs(50, "", "55") == true
	inline bool IsInRangedOs(OperatingSystem p_CurrentOs, const CString & p_GreaterThan, const CString & p_SmallerThan)
	{
		int l_GreaterThan = -10000;
		int l_SmallerThan = 10000;

		CString l_tmp;
		int l_retScanf;

		l_tmp = p_GreaterThan;
		l_tmp.Trim();
		if (l_tmp.GetLength() > 0)
		{
			l_retScanf = sscanf(l_tmp,"%d",&l_GreaterThan);
			if (l_retScanf != 1)
				throw -1;
		}

		l_tmp = p_SmallerThan;
		l_tmp.Trim();
		if (l_tmp.GetLength() > 0)
		{
			l_retScanf = sscanf(l_tmp,"%d",&l_SmallerThan);
			if (l_retScanf != 1)
				throw -1;
		}

		if (p_CurrentOs > l_GreaterThan && p_CurrentOs < l_SmallerThan)
			return true;
		else
			return false;
	}


	// Structure used to store enumerated languages and code pages.
	struct LANGANDCODEPAGE 
	{
	unsigned short wLanguage; //WORD
	unsigned short wCodePage; //WORD
	};

	inline LCID GetOperatingSystemLCID()
	{
		//per ulteriori informazioni vedere :
		// http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q181/6/04.asp&NoWebContent=1
		// Microsoft Knowledge Base Article - 181604
		// HOWTO: Determine Default Language ID of Windows 95 or WinNT
		//
		//return GetSystemDefaultLCID(); NO Questa funzione restituisce la lingua impostata di default dal pannello di controllo

		unsigned long dwVerHnd, dwVerInfoSize = 0;
		void * l_bufferVersionInfo = NULL;
		VS_FIXEDFILEINFO* lpvi = NULL;
		unsigned int iLen = 0;

		LANGANDCODEPAGE translation;

		//SystemPath
		TCHAR l_bufferSystem[MAX_PATH+1];
		ZeroMemory(l_bufferSystem,MAX_PATH+1);
		GetSystemDirectory(l_bufferSystem, MAX_PATH+1);
		CString l_UserExePath = PathCombineCustom(l_bufferSystem, "user.exe");

		dwVerInfoSize = GetFileVersionInfoSize(l_UserExePath, &dwVerHnd);
		if (dwVerInfoSize <= 0)
			throw -1;

		l_bufferVersionInfo = malloc( dwVerInfoSize );
		if (l_bufferVersionInfo == NULL)
			throw -1;

		BOOL l_ret = GetFileVersionInfo(l_UserExePath, dwVerHnd, dwVerInfoSize,l_bufferVersionInfo);
		if (l_ret == FALSE)
			throw -1;

		if (  VerQueryValue(l_bufferVersionInfo,"\\VarFileInfo\\Translation",(void**)&lpvi, &iLen) 
			&& iLen >= sizeof(LANGANDCODEPAGE))
		{
			translation = *(LANGANDCODEPAGE*)lpvi;

			free(l_bufferVersionInfo);
			l_bufferVersionInfo = NULL;

			return translation.wLanguage;
		} 

		throw -1;
	}

	//determina se nella stringa passata in formato: 1033,1040,!2033 (in pratica i LCID separati da virgolo supportando anche il ! (not)
	// � presente il locale del sistema operativo
	inline bool IsOperatingSystemLCID(const CString & p_FilterLCID)
	{
		if (p_FilterLCID.GetLength() <= 0)
			return true;

		LCID l_id = GetOperatingSystemLCID();
		LCID l_filterId;

		bool l_bIsOperatingSystemLCID = false;

		std::vector<std::string> l_ArrayLcid;
		split_string((LPCTSTR)p_FilterLCID, ',', l_ArrayLcid);

		for (size_t i = 0; i < l_ArrayLcid.size(); i++)
		{
			if (l_ArrayLcid[i].size() > 0)
			{
				std::string l_CheckNot = l_ArrayLcid[i];
				std::string l_LCID;
				bool l_bNot;
				if ( strcmp("!", l_CheckNot.substr(0,1).data() ) == 0  )
				{
					l_LCID = l_ArrayLcid[i].substr(1, l_ArrayLcid[i].size()-1);
					l_bNot = true;
				}
				else
				{
					l_LCID = l_ArrayLcid[i];
					l_bNot = false;
				}

				l_filterId = -1;
				if ( sscanf(l_LCID.data(), "%d", &l_filterId)!= 1)
					throw -1;

				if (l_bNot)
				{
					if (l_id == l_filterId)
						l_bIsOperatingSystemLCID = l_bIsOperatingSystemLCID || false;
					else
						l_bIsOperatingSystemLCID = l_bIsOperatingSystemLCID || true;
				}
				else
				{
					if (l_id == l_filterId)
						l_bIsOperatingSystemLCID = l_bIsOperatingSystemLCID || true;
					else
						l_bIsOperatingSystemLCID = l_bIsOperatingSystemLCID || false;
				}
			}
			else
				l_bIsOperatingSystemLCID = l_bIsOperatingSystemLCID & true;
		}

		return l_bIsOperatingSystemLCID;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

About the Author

Davide Icardi
Software Developer
Italy Italy
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 5 Jan 2004
Article Copyright 2003 by Davide Icardi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid