当前位置:编程学习 > C#/ASP.NET >>

求教如何得到桌面某个程序的安装路径

RT 请各位大大给予指导 苦思好久不解 555~ --------------------编程问答-------------------- /// <summary>
/// 获取已安装的软件列表
/// </summary>
/// <returns></returns>
/// <remarks></remarks>
public List<string> GetInstalledSoftwaresList()
{
    try {
        List<string> InstalledSoftwareList = new List<string>();
        var _with1 = InstalledSoftwareList;
        _with1.Add("[[已安装的软件]]");
        //HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
        RegistryKey Keys = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
        string[] S = Keys.GetSubKeyNames;
        foreach (string tms in S) {
            Keys = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + tms, true);
            string K = Keys.GetValue("DisplayName", "");
            if (K.Length != 0) {
                _with1.Add("[" + K + "]");
                _with1.Add(K + "/");
            }
            K = Keys.GetValue("DisplayVersion", "");
            if (K.Length != 0) {
                _with1.Add("版本:/" + K);
            }
            K = Keys.GetValue("Publisher", "");
            if (K.Length != 0) {
                _with1.Add("发布者:/" + K);
            }
            K = Keys.GetValue("InstallLocation", "");
            if (K.Length != 0) {
                _with1.Add("安装目录:/" + K);
            }
            K = Keys.GetValue("InstallDate", "");
            if (K.Length != 0) {
                _with1.Add("安装日期:/" + K);
            }
            Keys.Close();
        }
    } catch {
    }
    return InstalledSoftwareList;
} --------------------编程问答-------------------- 一、如果你开发的C/S程序,那么编写起来不是很复杂,方法如下: 1、获得路径的方法(博友deerchao提到过的) 请在注册表编辑器中查看以下条目: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall(找到你需要的软件名称,查找键名为[UninstallString]中的值,舍弃最后的文件,前面一般就是安装路径了) 关于读写注册表的方法,网上有很多,请结合(1)、(2): (1)、using Microsoft.Win32;//注意添加此引用 RegistryKey rk = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\..."); (2)、请访问网页,此网页中有读注册表的方法与(1)相同,同时还有写注册表的方法http://blog.csdn.net/jinru2560/archive/2006/01/13/578021.aspx 2、复制文件夹的方法 这里就不重复写代码了,无论使用API函数还是使用程序开发都很长,提供两个网页,代码很详细,你看看是否能明白和理解: (1)、http://zhidao.baidu.com/question/51770634.html (2)、http://topic.csdn.net/t/20050711/16/4137173.html 3、调用某个exe运行的方法 System.Diagnostics.Process.Start("*****");//*****是指你所要调用的exe文件的路径及文件全名。 4、当你结束自己的程序同时也需要结束使用第3点方法打开的某exe时,使用如下方法 private static void KillProcess(string strProName) { System.Diagnostics.Process[] pro = System.Diagnostics.Process.GetProcesses(); foreach (System.Diagnostics.Process IsProcedding in pro) { if (IsProcedding.ProcessName.ToUpper() == strProName)//strProName是第3点中打开的exe软件启动后的应用程序进程名,ToUpper()方法是将字符串名中字符全部转为大写英文字符 { IsProcedding.Kill(); } } } 二、如果开发的B/S程序,编写起来就较为复杂,因为你要用IE来操纵客户端。这里就不详述了,猜想你所寻求的应该是开发C/S模式下的这些问题的解决方法。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,