• 查询本地注册表,调用某后缀文件相应的执行程序,并打开文件


    以下是查询注册表信息的代码: 

    查找注册表中某后缀文件执行程序的代码
     1 private RegistryKeyStatus GetExePath(string suffix, ref string exePath)
     2 {
     3     RegistryKey regSuffixKey = Registry.ClassesRoot.OpenSubKey(suffix);
     4     if (regSuffixKey == null || regSuffixKey.GetValue(""== null)
     5         return RegistryKeyStatus.NonAvailable;
     6     string playerKey = regSuffixKey.GetValue("").ToString();
     7     RegistryKey regPlayerKey = Registry.ClassesRoot.OpenSubKey(playerKey + "\\shell\\open\\command");
     8     if (regPlayerKey == null)
     9         return RegistryKeyStatus.RegKeyNotFound;
    10     string[] keys = regPlayerKey.GetValue("").ToString().Split('"');
    11     foreach (string key in keys)
    12     {
    13         if (!string.IsNullOrEmpty(key.Trim()))
    14         {
    15             exePath = key;
    16             break;
    17         }
    18     }
    19     return RegistryKeyStatus.Available;
    20 }
    21  public enum RegistryKeyStatus
    22 {
    23     Available = 0,//可用
    24      NonAvailable = 1,//无可用
    25     RegKeyNotFound = 2,//未找到注册键
    26 }

     执行的话,只需要调用Process.Start()就可以了。 

    1 RegistryKeyStatus regKeyStatus = GetExePath(suffix, ref exePath);
    2 Process.Start(exePath, "\"" + filePath + "\"");

    注:上面的"\""一定要加,否则地址中有空格就可能找不到相应文件。

                                   --小小的,有大大的梦想!
  • 相关阅读:
    AtCoder Beginner Contest 113 D Number of Amidakuji
    UVA
    mt19937 -- 高质量随机数
    牛客网NOIP赛前集训营-提高组(第七场)C 洞穴
    牛客OI周赛4-提高组 C 战争(war)
    牛客OI周赛4-提高组 B 最后的晚餐(dinner)
    bzoj 4318 || 洛谷P1654 OSU!
    Tourists Codeforces
    bzoj 1791 [Ioi2008]Island 岛屿
    洛谷 P2231 [HNOI2002]跳蚤
  • 原文地址:https://www.cnblogs.com/ztlyz/p/1802371.html
Copyright © 2020-2023  润新知