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!