Windows Develop Bookmark and Share   
 index > Windows Forms General > How to get the Installed path of a program
 

How to get the Installed path of a program

Hello

How to Take the Installed Path of a Program using vb.net, I have Know the application name, so why I Have to find out the Path of Program using the Application name

Thanks
Murali
MuraliAsok  Monday, September 21, 2009 4:36 AM
Following function will return InstalledPath of a program.

using System.Management;

private void Form1_Load(object sender, EventArgs e)
{
    MessageBox.Show(GetInstallLocation("Application Name"));

}

string GetInstallLocation(string appName)
{
    ManagementObjectSearcher MyWMIQuery = new ManagementObjectSearcher("SELECT * FROM Win32_Product WHERE Name='" + appName + "'");
    ManagementObjectCollection MyWMIQueryCollection = MyWMIQuery.Get();

    string installLocation = null;
    if (MyWMIQueryCollection.Count > 0)
    {
        foreach (ManagementObject MyMO in MyWMIQueryCollection)
        {
            installLocation = (MyMO["InstallLocation"] == null ? " " : MyMO["InstallLocation"].ToString());
            break;
        }

    }

    MyWMIQueryCollection = null;
    MyWMIQuery = null;
    return installLocation;
    }

Gaurav Khanna
Khanna Gaurav  Monday, September 21, 2009 11:59 AM
Also you can use value namedInstallLocation from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall


You can use My.Computer.Registry.GetValuefunction to get the value
Gaurav Khanna
Khanna Gaurav  Monday, September 21, 2009 12:12 PM
Following function will return InstalledPath of a program.

using System.Management;

private void Form1_Load(object sender, EventArgs e)
{
    MessageBox.Show(GetInstallLocation("Application Name"));

}

string GetInstallLocation(string appName)
{
    ManagementObjectSearcher MyWMIQuery = new ManagementObjectSearcher("SELECT * FROM Win32_Product WHERE Name='" + appName + "'");
    ManagementObjectCollection MyWMIQueryCollection = MyWMIQuery.Get();

    string installLocation = null;
    if (MyWMIQueryCollection.Count > 0)
    {
        foreach (ManagementObject MyMO in MyWMIQueryCollection)
        {
            installLocation = (MyMO["InstallLocation"] == null ? " " : MyMO["InstallLocation"].ToString());
            break;
        }

    }

    MyWMIQueryCollection = null;
    MyWMIQuery = null;
    return installLocation;
    }

Gaurav Khanna
Khanna Gaurav  Monday, September 21, 2009 11:59 AM
Also you can use value namedInstallLocation from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall


You can use My.Computer.Registry.GetValuefunction to get the value
Gaurav Khanna
Khanna Gaurav  Monday, September 21, 2009 12:12 PM

Application.StartupPath
Application.ExecutablePath


VB.NET to C# http://www.developerfusion.com/tools/convert/vb-to-csharp/
Se3ker385  Monday, September 21, 2009 4:51 PM

You can use google to search for other answers

Custom Search

More Threads

• Assigning MdiParent on OnHandleCreated results in Error creating window handle when the form is shown.
• Can you force a brush to paint over existing controls
• Cannot Reflect on custom Attribute
• Balloon Tooltip for Toolstrip items
• How to reuse a button ??Whats the logic behaind that?
• sin and cos
• richtextboxprintctrl delete key problem
• Sharing Forms Between AppDomains
• Different types of args
• HOW TO: attach PreProcessMessage to windows form or control