Targeting a higer version of .NET 11-25-2011, 10:42 AM
#1
ugh I wrote this out and accidentally hit refresh !@#
Most people like to target version 2.0 of the .NET framework, because it's on pretty much every PC at this point. However I like to use the newest version, because they generally include nice features I like to use. The problem is almost no one keeps up to date on their .NET versions unless they happen to install something else that needs the version you want to target. I solve this problem with what I call a "loader". Instead of distributing your binary you distribute the loader. I write mine in C++ so this will be geared towards that, but you can use what ever language you want that will execute.
Create a Win32 Console Application in VS.
Add a version checking class
Add a class to handle the installation of your program
In the .NET version checking class it's pretty simple to figure how what version is installed. Below are the registry checks you need to look for.
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4";
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5";
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3";
As you can probably guess the key that ends is v4 is present if version 4.0 is installed and so on down the line. Now if it's not found simply download the version you want to target and install it silently. You do this by passing /q /norestart to the .NET installer.
Assuming everything went fine in the .NET installation have your other installer class download your binary and execute it.
In the main function of your Win32 Console Application make sure to put the following code at the top so it hides the box during all of this.
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE );
The .NET installer is kind of big around 50mb or so, but that really shouldn't be a problem, because all of this is running in the background.
Hope this helps someone,
puma
Most people like to target version 2.0 of the .NET framework, because it's on pretty much every PC at this point. However I like to use the newest version, because they generally include nice features I like to use. The problem is almost no one keeps up to date on their .NET versions unless they happen to install something else that needs the version you want to target. I solve this problem with what I call a "loader". Instead of distributing your binary you distribute the loader. I write mine in C++ so this will be geared towards that, but you can use what ever language you want that will execute.
Create a Win32 Console Application in VS.
Add a version checking class
Add a class to handle the installation of your program
In the .NET version checking class it's pretty simple to figure how what version is installed. Below are the registry checks you need to look for.
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4";
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5";
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3";
As you can probably guess the key that ends is v4 is present if version 4.0 is installed and so on down the line. Now if it's not found simply download the version you want to target and install it silently. You do this by passing /q /norestart to the .NET installer.
Assuming everything went fine in the .NET installation have your other installer class download your binary and execute it.
In the main function of your Win32 Console Application make sure to put the following code at the top so it hides the box during all of this.
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE );
The .NET installer is kind of big around 50mb or so, but that really shouldn't be a problem, because all of this is running in the background.
Hope this helps someone,
puma

![[+]](https://sinister.li/images/modern/collapse_collapsed.png)