C# 获取常见软件的安装路径(调用注册表)
来源:互联网 发布:诺基亚c6 01视频软件 编辑:程序博客网 时间:2024/05/21 06:25
转自http://www.cnblogs.com/ustcwhc/archive/2011/11/18/2254367.html
很多软件安装位置不一样,但是他们基本上会在注册表的同一个位置写下自己的名字和程序路径,这个位置就是:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
所以只要去这个地方找软件路径就可以了。
你可以添加你知道的正确的文件名,就是它在注册表中的名字。比如office word在注册表中叫winword
最终拿到的是那个exe的完全路径,如果要文件夹的话就用Path.GetDirectoryName()就行了
public enum Softwares
{
//The names are the same with the registry names.
//You can add any software exists in the "regedit" path:
//HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
EXCEL, //Office Excel
WINWORD, //Office Word
MSACCESS, //Office Access
POWERPNT, //Office PowerPoint
OUTLOOK, //Office Outlook
INFOPATH, //Office InfoPath
MSPUB, //Office Publisher
VISIO, //Office Visio
IEXPLORE, //IE
ITUNES //Apple ITunes
//.........
}
public class SoftwareOperator
{
//When you do not want to use string name, then use the Enum instead
public static bool TryGetSoftwarePath(SoftwaressoftName, out string path)
{
return TryGetSoftwarePath(softName.ToString(),out path);
}
public static bool TryGetSoftwarePath(stringsoftName, 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", false);
//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.SecurityExceptionex)
{
throw new System.Security.SecurityException("You have no right to read the registry!", ex);
}
catch (Exceptionex)
{
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;
}
}
}
- C# 获取常见软件的安装路径(调用注册表)
- C# 获取常见软件的安装路径(调用注册表)
- C# 获取常见软件的安装路径(调用注册表)
- C#获取常见软件的安装路径(调注册表)
- c#获取安装的软件和路径(注册表)
- 利用C#访问注册表获取软件的安装路径
- 根据注册表获取软件安装路径
- C#读取注册表,获取本机安装的软件清单
- 调用Windows接口访问注册表来获取程序安装路径
- 获取软件在注册表的安装信息
- C#读取注册表获得安装的软件
- c#获取软件在注册表中的安装信息
- c#获取常见路径
- VC通过注册表获取获取某个应用程序的安装路径
- 读取注册表中某个软件安装路径的字段值
- c++获取注册表中程序的安装路径
- 利用注册表获取本机安装的软件
- 用注册表修改软件默认安装路径
- 服务器apache下绑定域名到指定目录的方法
- ORACLE 数据泵技术
- linux学习基本步骤
- SR-IOV
- MT4编程开发(2)
- C# 获取常见软件的安装路径(调用注册表)
- Java创建线程的两个方法
- Sql:請假跨月份問題,或跨年份問題 日期部分边界
- MT4编程(4)
- 想成为Java高手的25个学习目标
- Android APK反编译详解
- C# Winform应用程序占用内存较大解决方法整理
- Win8离线安装.Net Framework 3.5时出现错误: 0x800f0906 解决办法。
- Python 常用模块收集