Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends I want to know the default .net frameworks of every windows.
So i can i make an installer via c# for example .net 1.0 i suppose would be common in all of them?
Can i instal .net framework4 and windows installer from c# silently?
Posted
Updated 17-Jan-13 4:56am
v2

Microsoft provides a comprehensive FrameWork installer that takes into account the Windows OS it installs to [^].

Yes, you can use FrameWork 4 on Windows XP OS with SP3, or, on Vista with SP1, or later, etc.

The article linked to above will give you all the details.

Your statement about "silent install" from C# doesn't quite make sense to me. Visual Studio can make an installer: what doesn't that do for you that you need done ?

Here's another recent question on CP Q&A that asked (and was answered) regarding "silent install" of the FrameWork: [^].

There are lots of resources on the net for "silent install" of the FrameWork: [^].

And, there's the option of using "ClickOnce" [^]. Be sure and examine the section in that article titled "Browser Support" [^].
 
Share this answer
 
Comments
F.moghaddampoor 17-Jan-13 11:54am    
The problem is i have more packages to be installed. like microsoft Sql server localdb 2012 that is not supported in visual studio 2010 setup project.
BillWoodruff 17-Jan-13 12:23pm    
Sorry, my friend, I can't help you with that one (I've never written an installer, although I did work for Addison-Wesley as a paid technical editor on Brian Noyes' book on ClickOnce), but I do encourage you to use the CodeProject search engine. It's very possible someone here has had the same issues you are dealing with.
F.moghaddampoor 17-Jan-13 14:04pm    
I have found my answer see below
This should help: http://en.wikipedia.org/wiki/.NET_Framework#Versions[^] - it lists what version shipped with each OS - if the OS is not listed, then it didn;t get .NET as standard, like XP for example. But that doesn't mean that the highest version installed on a particular machine is as listed - it is a simple matter to install say V3.5 on XP. The best thing to do is to check the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

If you iterate the sub keys, it will give you the highest version installed.

You can't install .NET from C# reliably at all: C# requires .NET to be installed in ordser to run. If you try to =run a C# program on an XP machine for example, it will not run at all unless .NET has been installed by a different app.

Why not just create a Setup and Deployment project? It will ensure the required .NET version is present for you.
 
Share this answer
 
Comments
F.moghaddampoor 17-Jan-13 11:54am    
The problem is i have more packages to be installed. like microsoft Sql server localdb 2012 that is not supported in visual studio 2010 setup project.
Hello friends i wanted to create an installer for one of my MSIs. SQL localdb 2012, and i wrote this:


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
using System.Configuration.Install;
using System.Diagnostics;
 
namespace EXE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            bool instalResult = false;
            timer1.Enabled = true;
            string strResult = "n";
            strResult=fncCheckRegistry();
            bool is64 = CheckCpuArcitecture();
            string appPath = Path.GetDirectoryName(Application.ExecutablePath);
            string strMsix86FileName = appPath + @"\x86\SqlLocaLDB.msi";
            string strMsix64FileName = appPath + @"\x64\SqlLocalDB_64.msi";
            //

            if (strResult != "y")
            {
                if (is64 == false)
                {
                    instalResult=fncInstal32(strMsix86FileName);
                }
            }
            if (strResult != "y")
            {
                if (is64 == true)
                {
                    instalResult = fncInstal32(strMsix64FileName);
                }
            }
            if (instalResult) timer1.Enabled = false;
            this.Close();
        }
        //
        public bool fncInstal32(string sMSIPath)
        {
            try
            {
                Console.WriteLine("Starting to install application");
                Process process = new Process();
                process.StartInfo.FileName = "msiexec.exe";
                process.StartInfo.Arguments = string.Format(" /qf /i \"{0}\" ALLUSERS=1  IACCEPTSQLNCLILICENSETERMS=YES", sMSIPath);
                process.Start();
                process.WaitForExit();
                Console.WriteLine("Application installed successfully!");
                return true; //Return True if process ended successfully
            }
            catch
            {
                Console.WriteLine("There was a problem installing the application!");
                return false;  //Return False if process ended unsuccessfully
            }
        }
        public bool CheckCpuArcitecture()
        {
            bool is64 = System.Environment.Is64BitOperatingSystem;
            return is64;
        }
        //
        public string fncCheckRegistry()
        {
            string strResult = "n";
 
            using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server 2012 Redist\MSSQL11E.LOCALDB\1033\CurrentVersion"))
                if (Key != null)
                {
 
                    strResult= "y";
                }
                else
                {
                    strResult= "n";
                }
 
            return strResult;
        }
        bool x = false;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value==100) x=true;
            if(!x) progressBar1.Value++;
            if (progressBar1.Value==0) x=false;
            if(x) progressBar1.Value--;
        }
    }
}


This checks cpu Arcitecture and if my msi is installed before.
the problem begins here.
I used this project as an exe in custom actions in a another setup project.
in the second setup project i install .net framework 4 and windows installer.
but i added custom action in the commit part of the setup.
So after the first installation finished(not completely the finish button is not clicked) the second setup that install sql server will begin, but how unlucky i am after two days of thinking on my problem it warns me about having two setup working together!!!
What should i do friends? do you have any suggestion?
How can i close the base uninstaller at the end of installation and open another process?


I have find my answer:

Well we create an installer class and we write this in it:





C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
 

namespace OpenWeb
{
    [RunInstaller(true)]
 
    public partial class Installer1 : System.Configuration.Install.Installer
    {
        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
        }
 
        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            System.Diagnostics.Process.Start(Context.Parameters["TARGETDIR"].ToString() + "Exe.exe");
            // Very important! Removes all those nasty temp files.
            base.Dispose();
        }
 
        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }
 
        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
        }
 
        public Installer1()
        {
            InitializeComponent();
        }
    }
}



then we create our setup and we add our exe file and we add the installer class by adding primary output.
now we add custom action in commit and install by adding primary output there too.
now we add this /TARGETDIR="[TARGETDIR]\" to our custom action data for both of install and commit part.
now we build our setup.
Enjoy
 
Share this answer
 
v3
Comments
BillWoodruff 17-Jan-13 19:05pm    
If you found your complete solution, I'm happy for you :)

My question is: did you find your complete solution ? I'm not totally clear that you did.

While I am not technically qualified in writing installers in .NET, if other folks here, who are qualified, think your solution is of general use to other people, then, may I suggest you think of creating a Tip/Trick for CodeProject, so others can share what you have found. I will be happy to help you edit the Tip/Trick for clarity, if you like.

But first, we need an opinion from someone here with experience in installer writing as to whether this is a generally useful solution, if, indeed, you have found your solution.

cheers, Bill
F.moghaddampoor 17-Jan-13 19:16pm    
Well i suppose i should use the least .net framework to create my installer, but i created a mixed installer, some of the components like .net framework 4 and windows installer would be installed by visual studio setup project and some others like sql server 2012 local db should be installed by our hands. so as i didn't know xml, i decided to create a c# program with .net frame work 2.0, it would be the exe file that would be runned by visual studio custom action. so why should we bother our self to write a installer, we use a mixed approach here.
but i would be glad to help you to create a tip and trick.
BillWoodruff 17-Jan-13 21:47pm    
"I would be glad to help you to create a tip and trick." Thanks, for your kind offer, but I am not really interested in delving into installer writing; I could only help out with making sure your explanation was in well organized, clear, English.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900