c# 打开其他应用程序方法

本文介绍两种在未知具体路径的情况下查找程序路径的方法:一是利用桌面快捷方式启动程序;二是通过读取注册表信息来获取程序的实际安装位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不知道具体的路径情况下

方法一:如果知道桌面的快捷方式

 System.Diagnostics.Process.Start(@"C:\Users\lyylz\Desktop\360云盘.lnk");


方法二:通过注册表,找到路径
            Version currentVersion = Environment.OSVersion.Version;
            Version compareToVersion = new Version("6.2");
            if (currentVersion.CompareTo(compareToVersion) >= 0)
            {//win8及其以上版本的系统
                   using (RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store"))
                   {
                       if (key != null)
                       {
                           string[] sname = key.GetValueNames();
                           for (int i = 0; i < sname.Length; i++)
                           {

                               if (sname[i].ToString().Substring(0, 2) == "C:" || sname[i].ToString().Substring(0, 2) == "D:" || sname[i].ToString().Substring(0, 2) == "E:" || sname[i].ToString().Substring(0, 2) == "F:" || sname[i].ToString().Substring(0, 2) == "G:" || sname[i].ToString().Substring(0, 2) == "H:")

//查到的注册表可能有SIGN.MEDIA=2CE47846 VS2010\setup.exe,E:\win10\Opera\launcher.exe,需要判断

                               {
                                   int ss = sname[i].ToString().LastIndexOf("\\");
                                   string s = sname[i].ToString().Substring(ss, sname[i].Length - ss);
                                   string sss = s.Substring(1, s.Length - 1);
                                    if (sss == "baiduyunguanjia.exe")
                                   {
                                       MessageBox.Show(sname[i].ToString());
                                       continue;
                                   }
                               }
                           }
                       }
                   }
               }
            else{ 
// win7及其以下版本的系统
 using (RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", false))
                    {
                        if (key != null)
                        {
                            //foreach (string keyName in key.GetSubKeyNames())
                            //{
                            string[] ssss = key.GetSubKeyNames();
                            for (int i = 0; i < ssss.Length; i++)
                            {
                                using (RegistryKey key2 = key.OpenSubKey("百度云管家", false))
                                {
                                    if (key2 != null)
                                    {
                                        string softwareName = key2.GetValue("DisplayName", "").ToString();
                                        string installLocation = key2.GetValue("InstallLocation", "").ToString();
                                        if (!string.IsNullOrEmpty(installLocation))
                                        {
                                            //this.textBox1.AppendText(string.Format("软件名:{0} -- 安装路径:{1}\r\n", softwareName, installLocation));
                                            string lu = installLocation.ToString();
                                            string pp = lu.Remove(0, 1);
                                            string ppp = lu.Remove(lu.Length - 1, 1);
                                            Regex regex = new Regex("\"[^\"]*\"");
                                            string result = regex.Match(installLocation).Value.Replace("\"", "");
                                            this.textBox1.Text = result + @"\baiduyunguanjia.exe";
                                        }
                                    }
                                }
                            }
                        }
                    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值