ASP.net the registry to detect whether or not to install Office (Thunderbolt/qq is installed)

Source: Internet
Author: User
Tags win32

Detect if Office is installed and get installation path and installation version

The code is as follows Copy Code

#region Detect if Office is installed


<summary>


Detecting whether Office is installed


</summary>


<param name= "Office_version" > Get and Return to the installed Office version </param>


<returns></returns>


public static bool Isinstalloffice (out string office_version, out string office_path)


{


BOOL result = FALSE;


String Str_officepath = String. Empty;


String str_officeversion = String. Empty;


Office_version = string. Empty;


Office_path = string. Empty;





Getofficepath (out of Str_officepath, out str_officeversion);


if (!string. IsNullOrEmpty (Str_officepath) &&!string. IsNullOrEmpty (str_officeversion))


{


result = true;


Office_version = str_officeversion;


Office_path = Str_officepath;


}


return result;


}





<summary>


Gets and returns the currently installed Office version and installation path


</summary>


<param name= "Str_officepath" >office installation path </param>


<param name= "str_officeversion" >office installation version </param>


private static void Getofficepath (out string str_officepath, out string str_officeversion)


{


String Str_patheresult = String. Empty;


String Str_versionresult = String. Empty;


String str_keyname = "Path";


Object objresult = null;


Microsoft.Win32.RegistryValueKind regvaluekind;//Specifies the data type used to store values in the registry, or the data type that identifies a value in the registry.


Microsoft.Win32.RegistryKey RegKey = null;//represents an item-level node in the Windows registry (Registry object?)


Microsoft.Win32.RegistryKey regsubkey = null;


Try


{


RegKey = microsoft.win32.registry.localmachine;//Read HKEY_LOCAL_MACHINE Entry


if (Regsubkey = null)


{//office97


Regsubkey = Regkey.opensubkey (@ "Softwaremicrosoftoffice8.0commoninstallroot", false);//If the bool value is true, read and write to the open item, Otherwise open for read-only


Str_versionresult = "Office97";


Str_keyname = "OfficeBin";


}


if (Regsubkey = null)


{//office2000


Regsubkey = Regkey.opensubkey (@ "Softwaremicrosoftoffice9.0commoninstallroot", false);


Str_versionresult = "Pffice2000";


Str_keyname = "Path";


}


if (Regsubkey = null)


{//officexp


Regsubkey = Regkey.opensubkey (@ "Softwaremicrosoftoffice10.0commoninstallroot", false);


Str_versionresult = "OfficeXP";


Str_keyname = "Path";


}





if (Regsubkey = null)


{//office2003


Regsubkey = Regkey.opensubkey (@ "Softwaremicrosoftoffice11.0commoninstallroot", false);


Str_versionresult = "Office2003";


Str_keyname = "Path";


Try


{


Objresult = Regsubkey.getvalue (str_keyname);


Regvaluekind = Regsubkey.getvaluekind (str_keyname);


}


catch (Exception ex)


{


Regsubkey = null;


}


}





if (Regsubkey = null)


{//office2007


Regsubkey = Regkey.opensubkey (@ "Softwaremicrosoftoffice12.0commoninstallroot", false);


Str_versionresult = "Office2007";


Str_keyname = "Path";


}


Objresult = Regsubkey.getvalue (str_keyname);


Regvaluekind = Regsubkey.getvaluekind (str_keyname);


if (Regvaluekind = = Microsoft.Win32.RegistryValueKind.String)


{


Str_patheresult = Objresult.tostring ();


}


}


catch (Exception ex)


{


Loghelper.writelogerror (ex. ToString ());


Throw ex;


}


Finally


{


if (RegKey!= null)


{


Regkey.close ();


RegKey = null;


}





if (Regsubkey!= null)


{


Regsubkey.close ();


Regsubkey = null;


}


}


Str_officepath = Str_patheresult;


Str_officeversion = Str_versionresult;


}


#endregion

Similarly, detect QQ, Fetion, 360 antivirus, IE browser, Chrome, Office 2003/2007/2010

Just modify the validation

1 Regsubkey = Regkey.opensubkey (@ "Softwaretencentplatform_type_list3", false);//If the bool value is true, read or write to the open item, or read-only open
Can

Check whether QQ has been installed, through the registration form

The code is as follows Copy Code

View Code


#region Check whether QQ is installed


public static bool Isinstallqq (out string qqversion, out string qqpath)


{


BOOL result = FALSE;


String Str_qqpath = String. Empty;


String str_qqversion = String. Empty;


Qqversion = string. Empty;


Qqpath = string. Empty;





Getqqpath (out of Str_qqpath, out str_qqversion);


if (!string. IsNullOrEmpty (Str_qqpath) &&!string. IsNullOrEmpty (str_qqversion))


{


result = true;


Qqversion = str_qqversion;


Qqpath = Str_qqpath;


}


return result;


}





<summary>


///


</summary>


<param name= "Str_qqpath" ></param>


<param name= "Str_qqversion" ></param>


private static void Getqqpath (out string str_qqpath, out string str_qqversion)


{


String Str_patheresult = String. Empty;


String Str_versionresult = String. Empty;


String str_keyname = "Typepath";


Object objresult = null;


Microsoft.Win32.RegistryValueKind regvaluekind;//Specifies the data type used to store values in the registry, or the data type that identifies a value in the registry.


Microsoft.Win32.RegistryKey RegKey = null;//represents an item-level node in the Windows registry (Registry object?)


Microsoft.Win32.RegistryKey regsubkey = null;


Try


{


RegKey = microsoft.win32.registry.localmachine;//Read HKEY_LOCAL_MACHINE Entry


if (Regsubkey = null)


{//QQ


Regsubkey = Regkey.opensubkey (@ "Softwaretencentplatform_type_list3", false);//If the bool value is true, read or write to the open item, otherwise read-only open


Str_versionresult = "QQ";


Str_keyname = "Typepath";


}


Objresult = Regsubkey.getvalue (str_keyname);


Regvaluekind = Regsubkey.getvaluekind (str_keyname);


if (Regvaluekind = = Microsoft.Win32.RegistryValueKind.String)


{


Str_patheresult = Objresult.tostring ();


}


}


catch (Exception ex)


{


Loghelper.writelogerror (ex. ToString ());


Throw ex;


}


Finally


{


if (RegKey!= null)


{


Regkey.close ();


RegKey = null;


}





if (Regsubkey!= null)


{


Regsubkey.close ();


Regsubkey = null;


}


}


Str_qqpath = Str_patheresult;


Str_qqversion = Str_versionresult;


}


#endregion

Detect Thunder

The code is as follows Copy Code
#region Detect Thunder Thunderbolt


public static bool Isinstallthunder (out string thunderversion, out string thunderpath)


{


BOOL result = FALSE;


String Str_thunderpath = String. Empty;


String str_thunderversion = String. Empty;


Thunderversion = string. Empty;


Thunderpath = string. Empty;





Getthunderpath (out of Str_thunderpath, out str_thunderversion);


if (!string. IsNullOrEmpty (Str_thunderpath) &&!string. IsNullOrEmpty (str_thunderversion))


{


result = true;


Thunderversion = str_thunderversion;


Thunderpath = Str_thunderpath;


}


return result;


}





<summary>


///


</summary>


<param name= "Str_qqpath" ></param>


<param name= "Str_qqversion" ></param>


private static void Getthunderpath (out string str_thunderpath, out string str_thunderversion)


{


String Str_patheresult = String. Empty;


String Str_versionresult = String. Empty;


String str_keyname = "Path";


Object objresult = null;


Microsoft.Win32.RegistryValueKind regvaluekind;//Specifies the data type used to store values in the registry, or the data type that identifies a value in the registry.


Microsoft.Win32.RegistryKey RegKey = null;//represents an item-level node in the Windows registry (Registry object?)


Microsoft.Win32.RegistryKey regsubkey = null;


Try


{


RegKey = microsoft.win32.registry.localmachine;//Read HKEY_LOCAL_MACHINE Entry


if (Regsubkey = null)


{//QQ


Regsubkey = Regkey.opensubkey (@ "Softwarethunder Networkthunderoemthunder_backwnd", false);/ If the bool value is true, read or write to the open item, otherwise read-only open


Str_versionresult = "Thunder";


Str_keyname = "Path";


}


Objresult = Regsubkey.getvalue (str_keyname);


Regvaluekind = Regsubkey.getvaluekind (str_keyname);


if (Regvaluekind = = Microsoft.Win32.RegistryValueKind.ExpandString)


{


Str_patheresult = Objresult.tostring ();


}


}


catch (Exception ex)


{


Loghelper.writelogerror (ex. ToString ());


}


Finally


{


if (RegKey!= null)


{


Regkey.close ();


RegKey = null;


}


if (Regsubkey!= null)


{


Regsubkey.close ();


Regsubkey = null;


}


}


Str_thunderpath = Str_patheresult;


Str_thunderversion = Str_versionresult;


}


#endregion


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.