|
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 - Marked As Answer byAland LiMSFT, ModeratorTuesday, September 22, 2009 9:01 AM
- Proposed As Answer byKhanna Gaurav Monday, September 21, 2009 12:00 PM
-
| | 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- Marked As Answer byAland LiMSFT, ModeratorTuesday, September 22, 2009 9:01 AM
- Proposed As Answer byKhanna Gaurav Monday, September 21, 2009 12:13 PM
-
| | 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 - Marked As Answer byAland LiMSFT, ModeratorTuesday, September 22, 2009 9:01 AM
- Proposed As Answer byKhanna Gaurav Monday, September 21, 2009 12:00 PM
-
| | 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- Marked As Answer byAland LiMSFT, ModeratorTuesday, September 22, 2009 9:01 AM
- Proposed As Answer byKhanna Gaurav Monday, September 21, 2009 12:13 PM
-
| | 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 |
|