Website installation and packaging software environment detection and installation [2]

Source: Internet
Author: User

This section focuses on detection and the next section on installation!

After a C # tool is created, the framework environment does not need to be detected or installed. If this is not used, the tool cannot run.

Here we provide several detection scopes:

I. Check the operating system version

2. Check the IIS version

Iii. Check the framework Version

4. Check whether the RAR tool is installed

The specific implementation is as follows:

 

I. Check the operating system version:

 

We can get the OS Version through: System. Environment. OSVersion. Version.

Then, based on the version number, we can determine if else if or switch Branch:

 

Code

Public static string GetOSystemName ()
{
Return GetOSystemNameByVersion (System. Environment. OSVersion. Version) + "\ r \ n" + System. Environment. OSVersion. ServicePack;
}
Private static string GetOSystemNameByVersion (Version version)
{
If (version. Major = 5 & version. Minor = 2)
{
Return "Microsoft Windows Server 2003 ";
}
Else if (version. Major = 5 & version. Minor = 1)
{
Return "Microsoft Windows XP ";
}
Else if (version. Major = 5 & version. Minor = 0)
{
Return "Microsoft Windows 2000 ";
}
Else if (version. Major <= 4)
{
Return "Microsoft Windows NT ";
}
Return "unknown ";
}

 

 

2. Check the IIS version

 

The Registry is used for judgment:

We get

Main version MajorVersion and

Minor version number MinorVersion to determine the IIS version

 

Code

Public static string GetIISVerstion ()
{
RegistryKey key = Registry. LocalMachine. OpenSubKey (@ "SOFTWARE \ Microsoft \ INetStp ");
If (key = null) {return "";}
Return Convert. ToString (key. GetValue ("MajorVersion") + "." + Convert. ToString (key. GetValue ("MinorVersion "));
}

 

 

Iii. Check the framework Version

 

Like IIS detection, you can perform registry Detection:

Registry path:

Version 1.1: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ NET Framework Setup \ NDP \ v1.1.4322

Version 2.0: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ NET Framework Setup \ NDP \ v2.0.50727

Version 3.0: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ NET Framework Setup \ NDP \ v3.0 \ Setup

Version 3.5: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ NET Framework Setup \ NDP \ v3.5

You only need to determine whether the registry node exists! For more information about the code, see IIS detection.

 

Iv. RAR tool Detection

 

In this case, I have checked the common installation path of the rar.exe file to determine the detection:

Common Path: C: \ Program Files \ WinRAR \ WinRAR.exe

The path of the d drive and the E drive is also detected here:

 

Code

Public static bool IsFileExistsByCDE (string path)
{
Bool exists = true;
If (! System. IO. File. Exists (path ))
{
Path = path. Replace ("C:", "D :");
If (! System. IO. File. Exists (path ))
{
Path = path. Replace ("D:", "E :");
If (! System. IO. File. Exists (path ))
{
Exists = false;
}
}
}
Return exists;
}

 

After finishing, close the job!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.