/// <summary> /// CompareVerbActionOpen is a helper function used to perform locale specific /// comparison of the verb action Open exposed by various control panel items. /// </summary> /// <param name="verbActionName">Locale specific verb action exposed by the control panel item.</param> /// <returns>True if the control panel item supports verb action open or else returns false.</returns> private static bool CompareVerbActionOpen(string verbActionName) { if (s_verbActionOpenName == null) { const string allItemFolderPath = ControlPanelShellFolder + "\\0"; IShellDispatch4 shell2 = (IShellDispatch4) new Shell(); Folder2 allItemFolder = (Folder2)shell2.NameSpace(allItemFolderPath); FolderItems3 allItems = (FolderItems3)allItemFolder.Items(); foreach (ShellFolderItem item in allItems) { string canonicalName = (string)item.ExtendedProperty("System.ApplicationName"); canonicalName = !String.IsNullOrEmpty(canonicalName) ? canonicalName.Substring(0, canonicalName.IndexOf("\0", StringComparison.OrdinalIgnoreCase)) : null; if (canonicalName != null && canonicalName.Equals(RegionCanonicalName, StringComparison.OrdinalIgnoreCase)) { // The 'Region' control panel item always has '&Open' (english or other locale) as the first verb name s_verbActionOpenName = item.Verbs().Item(0).Name; break; } } Dbg.Assert(s_verbActionOpenName != null, "The 'Region' control panel item is available on all SKUs and it always " + "has '&Open' as the first verb item, so VerbActionOpenName should never be null at this point"); } return(s_verbActionOpenName.Equals(verbActionName, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Get the category number and name map /// </summary> internal void GetCategoryMap() { if (CategoryMap.Count != 0) { return; } IShellDispatch4 shell2 = (IShellDispatch4) new Shell(); Folder2 categoryFolder = (Folder2)shell2.NameSpace(ControlPanelShellFolder); FolderItems3 catItems = (FolderItems3)categoryFolder.Items(); foreach (ShellFolderItem category in catItems) { string path = category.Path; string catNum = path.Substring(path.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1); CategoryMap.Add(catNum, category.Name); } }
internal void GetCategoryMap() { if (this.CategoryMap.Count == 0) { IShellDispatch4 variable = CreateShellImpl(); Folder2 variable1 = (Folder2)variable.NameSpace("shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}"); FolderItems3 variable2 = (FolderItems3)variable1.Items(); foreach (ShellFolderItem variable3 in variable2) { string path = variable3.Path; string str = path.Substring(path.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1); this.CategoryMap.Add(str, variable3.Name); } return; } else { return; } }
internal static void Initialize() { try { iShellDispatch4 = (IShellDispatch4)Activator.CreateInstance( Type.GetTypeFromProgID("Shell.Application")); // Using SHGetSetSettings would be much better in performance but the results are not accurate. // We have to go for the shell interface in order to receive the correct settings: // https://docs.microsoft.com/en-us/windows/win32/shell/ishelldispatch4-getsetting const int SSF_SHOWALLOBJECTS = 0x00000001; hideHiddenEntries = !iShellDispatch4.GetSetting( SSF_SHOWALLOBJECTS); const int SSF_SHOWSUPERHIDDEN = 0x00040000; hideSystemEntries = !iShellDispatch4.GetSetting( SSF_SHOWSUPERHIDDEN); } catch (Exception ex) { if (ex is ArgumentException || ex is NotSupportedException || ex is TargetInvocationException || ex is MethodAccessException || ex is MemberAccessException || ex is InvalidComObjectException || ex is MissingMethodException || ex is COMException || ex is TypeLoadException) { #pragma warning disable CA1303 // Do not pass literals as localized parameters Log.Warn("Get Shell COM instance failed", ex); #pragma warning restore CA1303 //=> Exceptions not translated in logfile => OK } else { throw; } } }
private static bool CompareVerbActionOpen(string verbActionName) { string str; bool flag = false; if (!string.IsNullOrEmpty(verbActionName)) { if (ControlPanelItemBaseCommand.VerbActionOpenName == null) { new List <ShellFolderItem>(); string str1 = "shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0"; IShellDispatch4 variable = CreateShellImpl(); Folder2 variable1 = (Folder2)variable.NameSpace(str1); FolderItems3 variable2 = (FolderItems3)variable1.Items(); foreach (ShellFolderItem variable3 in variable2) { string str2 = (string)((dynamic)variable3.ExtendedProperty("System.ApplicationName")); if (str2 != null) { str = str2.Substring(0, str2.IndexOf("\0", StringComparison.OrdinalIgnoreCase)); } else { str = null; } str2 = str; if (str2 == null || !str2.Equals("Microsoft.RegionAndLanguage", StringComparison.OrdinalIgnoreCase)) { continue; } ControlPanelItemBaseCommand.VerbActionOpenName = verbActionName; break; } } flag = ControlPanelItemBaseCommand.VerbActionOpenName.Equals(verbActionName, StringComparison.OrdinalIgnoreCase); } return(flag); }
public List <LaunchInfo> GetInfo() { StringBuilder sbPath = new StringBuilder(255); NativeMethods.SHGetSpecialFolderPath(IntPtr.Zero, sbPath, NativeMethods.CSIDL_COMMON_STARTUP, false); var pathVariants = new [] { Environment.GetFolderPath(Environment.SpecialFolder.Startup), sbPath.ToString() }; var launchInfoList = new List <LaunchInfo>(); Stack <object> comObjects = new Stack <object>(); try { IShellDispatch4 shell = new IShellDispatch4(); comObjects.Push(shell); foreach (var path in pathVariants) { var shortcutFolder = shell.NameSpace(path); comObjects.Push(shortcutFolder); var items = shortcutFolder.Items(); comObjects.Push(items); foreach (FolderItem folderItem in items) { comObjects.Push(folderItem); if (!folderItem.IsLink) { continue; } ShellLinkObject lnk = folderItem.GetLink; comObjects.Push(lnk); if (!string.IsNullOrEmpty(lnk.Path)) { var info = _pathResolver.ResolvePath(lnk.Path, lnk.Arguments, LaunchInfoSource.StartUpMenu); launchInfoList.Add(info); } } } return(launchInfoList); } finally { while (comObjects.Count > 1) { Marshal.ReleaseComObject(comObjects.Pop()); } } }