C# 获取安装程序的路径

来源:互联网 发布:js文件编写格式 编辑:程序博客网 时间:2024/05/23 18:44

C#     获取安装程序的路径

 如下图:AFAMShell 位 我的应用程序

 代码如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics;using System.Threading;using Microsoft.Win32;namespace Project_Phoenix{    class Case    {        public static void KillProcess(string[] arrProcess)    // 杀进程方法        {             foreach(Process p in Process.GetProcesses())            {                for (int i = 0; i < arrProcess.Length; i++)                {                    if (p.ProcessName.ToString() == arrProcess[i])                    {                        p.Kill();                    }                }            }             Thread.Sleep(1000);        }        public static string  Get_AFAM_Path()    // 获取程序路径方法        {            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\AspenTech\AFAM\");            string ss = key.GetValue("AFAMShell").ToString();            return ss;        }    }}


写个 main 方法:

public static void  main()

{

       Console.WriteLine(Case.Get_AFAM_Path());

}