private static ShellCommandSoftware GetSoftware(RegistryKey appkey, string id) { ShellCommandSoftware soft = new ShellCommandSoftware { Id = id, Name = id }; RegistryKey subkey; string name = appkey.GetValue(string.Empty, string.Empty).ToString(); if (string.IsNullOrEmpty(name)) { name = ShellHelper.FileExtentionInfo(ShellHelper.AssocStr.FriendlyAppName, id); } if (string.IsNullOrWhiteSpace(name)) { name = appkey.GetValue("FriendlyTypeName", string.Empty).ToString(); name = GetText(name); } if (string.IsNullOrWhiteSpace(name)) { name = appkey.GetValue("DisplayName", string.Empty).ToString(); name = GetText(name); } if (!string.IsNullOrEmpty(name)) { soft.Name = name; } string value = ShellHelper.FileExtentionInfo(ShellHelper.AssocStr.DefaultIcon, id); soft.Icon = GetIcon(value); if (soft.Icon == null) { value = ShellHelper.FileExtentionInfo(ShellHelper.AssocStr.AppIconReference, id); soft.Icon = GetIcon(value); } if (soft.Icon == null) { subkey = appkey.OpenSubKey("DefaultIcon"); if (subkey != null) { value = subkey.GetValue(string.Empty, string.Empty).ToString(); soft.Icon = GetIcon(value); } } string appid = string.Empty; subkey = appkey.OpenSubKey("Application"); if (subkey != null) { appid = subkey.GetValue("AppUserModelID", string.Empty).ToString(); if (soft.Icon == null) { value = subkey.GetValue(string.Empty, string.Empty).ToString(); soft.Icon = GetIcon(value); } if (string.IsNullOrEmpty(soft.Name)) { value = subkey.GetValue("ApplicationName", string.Empty).ToString(); soft.Name = GetText(value); } } subkey = appkey.OpenSubKey("Shell"); if (subkey != null) { string defaultverb = subkey.GetValue(string.Empty, string.Empty).ToString(); string[] appverbs = subkey.GetSubKeyNames(); if (appverbs.Contains("OPEN", StringComparer.OrdinalIgnoreCase) && appverbs[0].ToUpperInvariant() != "OPEN") { string openOne = appverbs.First(T => T.ToUpperInvariant() == "OPEN"); int pos = Array.FindIndex(appverbs, T => T == openOne); appverbs[pos] = appverbs[0]; appverbs[0] = openOne; } foreach (string appverb in appverbs) { RegistryKey verbkey = subkey.OpenSubKey(appverb); ShellCommandVerb verb = GetVerb(verbkey, appverb, appid); if (verb != null) { soft.Verbs.Add(verb); if (defaultverb == appverb) { soft.Default = verb; } } } } if (string.IsNullOrEmpty(soft.Name)) { string application = appkey.GetValue(string.Empty, string.Empty).ToString(); if (!string.IsNullOrWhiteSpace(application)) { soft.Name = application; } else { soft.Name = id; } } if (soft.Verbs.Count <= 0) { return(null); } if (soft.Icon == null) { appid = soft.Verbs.FirstOrDefault(T => T.Command.ToUpperInvariant().Contains(".EXE"))?.Command; if (!string.IsNullOrEmpty(appid)) { appid = SplitCommandAndParameters(appid).Item1; soft.Icon = GetIcon(appid + ",0"); } } return(soft); }
private static ShellCommandVerb GetVerb(RegistryKey verbkey, string id, string appUserModeId) { if (id.ToUpperInvariant() == "RUNAS") { return(null); } //We are not taking DDE RegistryKey cmd = verbkey.OpenSubKey("ddeexec"); if (cmd != null && !string.IsNullOrEmpty(cmd.GetValue(string.Empty, string.Empty).ToString())) { return(null); } ShellCommandVerb verb = new ShellCommandVerb { Verb = id, Name = id }; string name = verbkey.GetValue("MUIVerb", string.Empty).ToString(); if (string.IsNullOrEmpty(name)) { name = verbkey.GetValue(string.Empty, string.Empty).ToString(); } if (name.StartsWith("@", StringComparison.Ordinal)) { StringBuilder outBuff = new StringBuilder(1024); if (SafeNativeMethods.SHLoadIndirectString(name, outBuff, outBuff.Capacity, IntPtr.Zero) == 0) { verb.Name = outBuff.ToString(); } } else { string locname = LocExtension.GetLocalizedValue <string>($"PresentationCore:ExceptionStringTable:{id}Text"); if (string.IsNullOrEmpty(locname)) { locname = LocExtension.GetLocalizedValue <string>(id); } if (!string.IsNullOrEmpty(locname)) { verb.Name = locname; } else if (!string.IsNullOrEmpty(name)) { verb.Name = name; } } if (id.ToUpperInvariant() == "RUNASUSER") { verb.Command = "cmd:runasuser"; return(verb); } cmd = verbkey.OpenSubKey("command"); if (cmd != null) { verb.Command = cmd.GetValue(string.Empty, string.Empty).ToString(); if (string.IsNullOrEmpty(verb.Command)) { name = cmd.GetValue("DelegateExecute", string.Empty).ToString(); if (!string.IsNullOrEmpty(name)) { cmd = Registry.ClassesRoot.OpenSubKey("CLSID\\" + name); if (cmd != null) { cmd = cmd.OpenSubKey("LocalServer32"); if (cmd != null) { name = cmd.GetValue(string.Empty, string.Empty).ToString(); if (!string.IsNullOrEmpty(name)) { verb.Command = name; } } if (string.IsNullOrEmpty(name)) { cmd = cmd.OpenSubKey("InProcServer32"); if (cmd != null) { name = cmd.GetValue(string.Empty, string.Empty).ToString(); if (!string.IsNullOrEmpty(name)) { verb.Command = "dll:" + name; } } } } } } } if (string.IsNullOrEmpty(verb.Command)) { if (!string.IsNullOrEmpty(appUserModeId)) { verb.Command = "Id:" + appUserModeId; } } if (string.IsNullOrEmpty(verb.Command)) { } return(verb); }