Obtain the software installation information in the registry.

Source: Internet
Author: User

/// <Summary> /// obtain the installation information of the SOFTWARE in the registry. // The SOFTWARE will enter its own installation information in the registry. // HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ App Paths /// </summary> /// <param name = "softName"> Software name </param> /// <param name = "path"> return to the software installation path </param> /// <returns> whether the registry installation path is found </returns> public static bool TryGetSoftwarePath (string softName, out string path) {string strPathResult = string. empty; string strKeyName = "";//" (Default) "key, which contains the intalled path object objResult = null; Microsoft. win32.RegistryValueKind regValueKind; Microsoft. win32.RegistryKey regKey = null; Microsoft. win32.RegistryKey regSubKey = null; try {// Read the key regKey = Microsoft. win32.Registry. localMachine; regSubKey = regKey. openSubKey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ App Paths \" + softName. toString () + ". exe ", fa Lse); // Read the path objResult = regSubKey. getValue (strKeyName); regValueKind = regSubKey. getValueKind (strKeyName); // Set the path if (regValueKind = Microsoft. win32.RegistryValueKind. string) {strPathResult = objResult. toString () ;}} catch (System. security. securityException ex) {throw new System. security. securityException ("You have no right to read the registry! ", Ex);} catch (Exception ex) {throw new Exception (" Reading registry error! ", Ex);} finally {if (regKey! = Null) {regKey. Close (); regKey = null;} if (regSubKey! = Null) {regSubKey. Close (); regSubKey = null ;}} if (strPathResult! = String. Empty) {// Found path = strPathResult; return true;} else {// Not found path = null; return false ;}}

 

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.