コード例 #1
0
 private void OpenPSAsAdminMethod()
 {
     StartProcess.StartInfo("C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", "-NoExit -Command Set-Location -LiteralPath " + "\'" + FolderPath + "\'", false, true);
 }
コード例 #2
0
 private void ShowHiddenMethod()
 {
     ExplorerAdvanced.SetValue("Hidden", 1.ToString(culture), RegistryValueKind.DWord);
     StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\xMenuTools.exe", "-refresh");
 }
コード例 #3
0
 private void OpenCmdAsUserMethod()
 {
     StartProcess.StartInfo("cmd.exe", "/s /k pushd " + "\"" + FolderPath + "\"");
 }
コード例 #4
0
 private void OpenCmdAsAdminMethod()
 {
     StartProcess.StartInfo("cmd.exe", "/s /k pushd " + "\"" + FolderPath + "\"", false, true);
 }
コード例 #5
0
        // Add Menu Items
        private void AddMenuItems()
        {
            try
            {
                RegistryKey xMenuToolsSettings = Registry.CurrentUser.CreateSubKey("SOFTWARE\\xMenuTools\\Settings");
                if (xMenuToolsSettings != null)
                {
                    object AttributesDirectoryBack = xMenuToolsSettings.GetValue("AttributesDirectoryBack");
                    if (AttributesDirectoryBack != null)
                    {
                        if (AttributesDirectoryBack.ToString() == "1")
                        {
                            xMenuToolsMenu.DropDownItems.Add(Attributes);
                            Attributes.DropDownItems.Add(AttributesMenu);
                            Attributes.DropDownItems.Add(new ToolStripSeparator());
                            Attributes.DropDownItems.Add(ShowHidden);
                            Attributes.DropDownItems.Add(HideHidden);
                            Attributes.DropDownItems.Add(ShowSystem);
                            Attributes.DropDownItems.Add(HideSystem);
                        }
                    }
                    object CommandLinesDirectoryBack = xMenuToolsSettings.GetValue("CommandLinesDirectoryBack");
                    if (CommandLinesDirectoryBack != null)
                    {
                        if (CommandLinesDirectoryBack.ToString() == "1")
                        {
                            xMenuToolsMenu.DropDownItems.Add(CommandLine);

                            string appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\WindowsApps\Microsoft.WindowsTerminal_8wekyb3d8bbwe\wt.exe");

                            if (File.Exists(appPath))
                            {
                                CommandLine.DropDownItems.Add(OpenTerminalAsUser);
                                CommandLine.DropDownItems.Add(OpenTerminalAsAdmin);
                                CommandLine.DropDownItems.Add(new ToolStripSeparator());
                            }

                            CommandLine.DropDownItems.Add(OpenCmdAsUser);
                            CommandLine.DropDownItems.Add(OpenCmdAsAdmin);
                            CommandLine.DropDownItems.Add(new ToolStripSeparator());
                            string programFiles    = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
                            string programFilesX86 = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%");
                            if (Directory.Exists(programFiles + @"\Git") || Directory.Exists(programFilesX86 + @"\Git"))
                            {
                                CommandLine.DropDownItems.Add(OpenGitAsUser);
                                CommandLine.DropDownItems.Add(OpenGitAsAdmin);
                                CommandLine.DropDownItems.Add(new ToolStripSeparator());
                            }
                            CommandLine.DropDownItems.Add(OpenPSAsUser);
                            CommandLine.DropDownItems.Add(OpenPSAsAdmin);
                        }
                    }
                    object SystemFoldersDirectoryBack = xMenuToolsSettings.GetValue("SystemFoldersDirectoryBack");
                    if (SystemFoldersDirectoryBack != null)
                    {
                        if (SystemFoldersDirectoryBack.ToString() == "1")
                        {
                            xMenuToolsMenu.DropDownItems.Add(SystemFolders);
                            SystemFolders.DropDownItems.Add(AppDataFolder);
                            SystemFolders.DropDownItems.Add(ProgramDataFolder);
                            SystemFolders.DropDownItems.Add(UserStartMenuFolder);
                            SystemFolders.DropDownItems.Add(AllUsersStartMenuFolder);
                            SystemFolders.DropDownItems.Add(UserTempFolder);
                        }
                    }
                    object PasteContentsDirectoryBack = xMenuToolsSettings.GetValue("PasteContentsDirectoryBack");
                    if (PasteContentsDirectoryBack != null)
                    {
                        if (PasteContentsDirectoryBack.ToString() == "1")
                        {
                            xMenuToolsMenu.DropDownItems.Add(PasteContents);
                        }
                    }
                    object FindWallpaperDirectoryBack = xMenuToolsSettings.GetValue("FindWallpaperDirectoryBack");
                    if (FindWallpaperDirectoryBack != null)
                    {
                        if (FindWallpaperDirectoryBack.ToString() == "1")
                        {
                            xMenuToolsMenu.DropDownItems.Add(FindWallpaper);
                        }
                    }
                    bool AllDisabled = true;
                    foreach (ToolStripMenuItem item in xMenuToolsMenu.DropDownItems)
                    {
                        if (item != null)
                        {
                            AllDisabled = false;
                        }
                    }
                    if (AllDisabled)
                    {
                        Menu.Dispose();
                    }
                }
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\xMenuTools.exe", "\"" + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.Source + Environment.NewLine + ex.GetBaseException() + Environment.NewLine + ex.TargetSite + "\"" + " -catchhandler");
            }
        }
コード例 #6
0
        // Create the Menu
        protected override ContextMenuStrip CreateMenu()
        {
            CheckUserSettings();

            // Main Menu
            using (Menu = new ContextMenuStrip())
            {
                Menu.Name = "xMenuToolsMenu";

                using (xMenuToolsMenu = new ToolStripMenuItem())
                {
                    xMenuToolsMenu.Name = "xMenuToolsMenu";

                    // CommandLine
                    using (CommandLine = new ToolStripMenuItem())
                    {
                        CommandLine.Text = Resources.CommandLines;
                        CommandLine.Name = "CommandLine";

                        // OpenTerminalAsUser
                        using (OpenTerminalAsUser = new ToolStripMenuItem())
                        {
                            OpenTerminalAsUser.Text = Resources.OpenTerminal;
                            OpenTerminalAsUser.Name = "OpenTerminalAsUser";
                        }
                        // OpenTerminalAsAdmin
                        using (OpenTerminalAsAdmin = new ToolStripMenuItem())
                        {
                            OpenTerminalAsAdmin.Text = Resources.OpenTerminalElevated;
                            OpenTerminalAsAdmin.Name = "OpenTerminalAsAdmin";
                        }

                        // OpenCmdAsUser
                        using (OpenCmdAsUser = new ToolStripMenuItem())
                        {
                            OpenCmdAsUser.Text = Resources.CommandPrompt;
                            OpenCmdAsUser.Name = "OpenCmdAsUser";
                        }
                        // OpenCmdAsAdmin
                        using (OpenCmdAsAdmin = new ToolStripMenuItem())
                        {
                            OpenCmdAsAdmin.Text = Resources.CommandPromptElevated;
                            OpenCmdAsAdmin.Name = "OpenCmdAsAdmin";
                        }

                        // OpenGitAsUser
                        using (OpenGitAsUser = new ToolStripMenuItem())
                        {
                            OpenGitAsUser.Text = Resources.OpenGitAsUser;
                            OpenGitAsUser.Name = "OpenGitAsUser";
                        }
                        // OpenGitAsAdmin
                        using (OpenGitAsAdmin = new ToolStripMenuItem())
                        {
                            OpenGitAsAdmin.Text = Resources.OpenGitAsAdmin;
                            OpenGitAsAdmin.Name = "OpenGitAsAdmin";
                        }

                        // OpenPSAsUser
                        using (OpenPSAsUser = new ToolStripMenuItem())
                        {
                            OpenPSAsUser.Text = Resources.OpenPSAsUser;
                            OpenPSAsUser.Name = "OpenPSAsUser";
                        }
                        // OpenPSAsAdmin
                        using (OpenPSAsAdmin = new ToolStripMenuItem())
                        {
                            OpenPSAsAdmin.Text = Resources.OpenPSAsAdmin;
                            OpenPSAsAdmin.Name = "OpenPSAsAdmin";
                        }
                    }
                    // Attributes
                    using (Attributes = new ToolStripMenuItem())
                    {
                        Attributes.Text = Resources.AttributesText;
                        Attributes.Name = "Attributes";

                        using (AttributesMenu = new ToolStripMenuItem())
                        {
                            AttributesMenu.Text = Resources.AttributesMenu;
                            AttributesMenu.Name = "AttributesMenu";
                        }
                        try
                        {
                            AttributesInfo.GetFileAttributes(FolderPath);
                        }
                        catch (Exception ex)
                        {
                            StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\xMenuTools.exe", "\"" + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.Source + Environment.NewLine + ex.GetBaseException() + Environment.NewLine + ex.TargetSite + "\"" + " -catchhandler");
                        }
                        SetInternalAttributes();
                    }
                    // System Folders
                    using (SystemFolders = new ToolStripMenuItem())
                    {
                        SystemFolders.Text = "System Folders";
                        SystemFolders.Name = "SystemFolders";

                        using (AppDataFolder = new ToolStripMenuItem())
                        {
                            AppDataFolder.Text = "AppData Folder";
                            AppDataFolder.Name = "AppDataFolder";
                        }
                        using (ProgramDataFolder = new ToolStripMenuItem())
                        {
                            ProgramDataFolder.Text = "ProgramData Folder";
                            ProgramDataFolder.Name = "ProgramDataFolder";
                        }
                        using (UserStartMenuFolder = new ToolStripMenuItem())
                        {
                            UserStartMenuFolder.Text = "Start Menu Folder";
                            UserStartMenuFolder.Name = "UserStartMenuFolder";
                        }
                        using (AllUsersStartMenuFolder = new ToolStripMenuItem())
                        {
                            AllUsersStartMenuFolder.Text = "All Users Start Menu Folder";
                            AllUsersStartMenuFolder.Name = "AllUsersStartMenuFolder";
                        }
                        using (UserTempFolder = new ToolStripMenuItem())
                        {
                            UserTempFolder.Text = "Temp Folder";
                            UserTempFolder.Name = "UserTempFolder";
                        }
                    }
                    // FindWallpaper
                    using (FindWallpaper = new ToolStripMenuItem())
                    {
                        FindWallpaper.Text = Resources.FindWallpaperText;
                        FindWallpaper.Name = "FindWallpaper";
                    }
                    // Paste Contents
                    using (PasteContents = new ToolStripMenuItem())
                    {
                        PasteContents.Text = "Paste clipboard text to file";
                        PasteContents.Name = "PasteContents";
                    }
                }
            }
            MenuDeveloper();

            return(Menu);
        }
コード例 #7
0
 private void TakeOwnershipMethod()
 {
     string[] array = SelectedItemPaths.Cast <string>().ToArray();
     StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\xMenuTools.exe", "\"" + array.ToStringArray(false) + "\"" + " -ownership", false, true);
 }
コード例 #8
0
 private void BlockFirewallMethod()
 {
     string[] array = SelectedItemPaths.Cast <string>().ToArray();
     StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\xMenuTools.exe", "\"" + array.ToStringArray() + "\" " + "-firewallfiles", false, true);
 }
コード例 #9
0
        protected override ContextMenuStrip CreateMenu()
        {
            CheckUserSettings();
            // Main Menu
            using (Menu = new ContextMenuStrip())
            {
                Menu.Name = "xMenuToolsFiles";

                using (xMenuToolsMenu = new ToolStripMenuItem())
                {
                    xMenuToolsMenu.Name = "xMenuToolsMenu";

                    // OpenNotepad
                    using (OpenNotepad = new ToolStripMenuItem())
                    {
                        OpenNotepad.Text = Resources.OpenNotepad;
                        OpenNotepad.Name = "OpenNotepad";
                    }
                    // BlockFirewall
                    using (BlockFirewall = new ToolStripMenuItem())
                    {
                        BlockFirewall.Text = Resources.BlockText;
                        BlockFirewall.Name = "BlockFirewall";
                    }
                    // CopyName
                    using (CopyName = new ToolStripMenuItem())
                    {
                        CopyName.Text = Resources.CopyNameText;
                        CopyName.Name = "CopyName";
                    }
                    // CopyPath
                    using (CopyPath = new ToolStripMenuItem())
                    {
                        CopyPath.Text = Resources.CopyPathText;
                        CopyPath.Name = "CopyPath";
                    }
                    // CopyPathURL
                    using (CopyPathURL = new ToolStripMenuItem())
                    {
                        CopyPathURL.Text = Resources.CopyPathURLText;
                        CopyPathURL.Name = "CopyPathURL";
                    }
                    // CopyLONGPath
                    using (CopyLONGPath = new ToolStripMenuItem())
                    {
                        CopyLONGPath.Text = Resources.CopyLONGPathText;
                        CopyLONGPath.Name = "CopyLONGPath";
                    }
                    // Attributes
                    using (Attributes = new ToolStripMenuItem())
                    {
                        Attributes.Name = "Attributes";

                        Attributes.Text = Resources.AttributesText;
                        // AttributesMenu
                        using (AttributesMenu = new ToolStripMenuItem())
                        {
                            AttributesMenu.Text = Resources.AttributesMenu;
                            AttributesMenu.Name = "AttributesMenu";
                        }
                        // Get : Set Attributes
                        string[] SelectedPath = SelectedItemPaths.Cast <string>().ToArray();
                        if (SelectedPath.Length > 1)
                        {
                            foreach (string item in SelectedPath)
                            {
                                try
                                {
                                    AttributesInfo.GetFileAttributes(item);
                                }
                                catch (Exception ex)
                                {
                                    StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\xMenuTools.exe", "\"" + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.Source + Environment.NewLine + ex.GetBaseException() + Environment.NewLine + ex.TargetSite + "\"" + " -catchhandler");
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                AttributesInfo.GetFileAttributes(SelectedPath.ToStringArray(false));
                            }
                            catch (Exception ex)
                            {
                                StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\xMenuTools.exe", "\"" + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.Source + Environment.NewLine + ex.GetBaseException() + Environment.NewLine + ex.TargetSite + "\"" + " -catchhandler");
                            }
                        }
                        SetFileAttributes();
                    }
                    // SymLink
                    using (SymLink = new ToolStripMenuItem())
                    {
                        SymLink.Text = Resources.CreateSymbolicLink;
                        SymLink.Name = "SymLink";
                    }
                    // TakeOwnership
                    using (TakeOwnership = new ToolStripMenuItem())
                    {
                        TakeOwnership.Text = Resources.TakeOwnershipText;
                        TakeOwnership.Name = "TakeOwnership";
                    }
                }
            }
            MenuDeveloper();

            return(Menu);
        }
コード例 #10
0
        // Add Menu Items
        private void AddMenuItems(string[] array)
        {
            try
            {
                // Disabler
                bool isShortcut   = false;
                bool isExeDllFile = false;
                foreach (string path in array)
                {
                    try
                    {
                        if (Path.GetExtension(path) == ".lnk")
                        {
                            isShortcut = true;
                        }
                        if (Path.GetExtension(path) != ".exe" && Path.GetExtension(path) != ".dll")
                        {
                            isExeDllFile = false;
                        }
                        if (Path.GetExtension(path) == ".exe" || Path.GetExtension(path) == ".dll")
                        {
                            isExeDllFile = true;
                        }
                        if (Directory.Exists(ShortcutHandler.GetShortcutTarget(path)))
                        {
                        }
                    }
                    catch (Exception ex)
                    {
                        EasyLogger.Error(ex.Message + " Error at ShortcutHandler.GetShortcutTarget(path)");
                        continue;
                    }
                }
                object OpenNotepadFiles = xMenuToolsSettings.GetValue("OpenNotepadFiles");
                if (OpenNotepadFiles != null)
                {
                    if (OpenNotepadFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(OpenNotepad);
                    }
                }
                object BlockWithFirewallFiles = xMenuToolsSettings.GetValue("BlockWithFirewallFiles");
                if (BlockWithFirewallFiles != null)
                {
                    if (BlockWithFirewallFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(BlockFirewall);
                    }
                }
                object CopyNameFiles = xMenuToolsSettings.GetValue("CopyNameFiles");
                if (CopyNameFiles != null && !isShortcut)
                {
                    if (CopyNameFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(CopyName);
                    }
                }
                object CopyPathFiles = xMenuToolsSettings.GetValue("CopyPathFiles");
                if (CopyPathFiles != null && !isShortcut)
                {
                    if (CopyPathFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(CopyPath);
                    }
                }
                object CopyURLFiles = xMenuToolsSettings.GetValue("CopyURLFiles");
                if (CopyURLFiles != null && !isShortcut)
                {
                    if (CopyURLFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(CopyPathURL);
                    }
                }
                object CopyLONGPathFiles = xMenuToolsSettings.GetValue("CopyLONGPathFiles");
                if (CopyLONGPathFiles != null && !isShortcut)
                {
                    if (CopyLONGPathFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(CopyLONGPath);
                    }
                }
                object AttributesFiles = xMenuToolsSettings.GetValue("AttributesFiles");
                if (AttributesFiles != null)
                {
                    if (AttributesFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(Attributes);
                        Attributes.DropDownItems.Add(AttributesMenu);
                        Attributes.DropDownItems.Add(new ToolStripSeparator());
                        Attributes.DropDownItems.Add(HiddenAttributes);
                        Attributes.DropDownItems.Add(SystemAttributes);
                        Attributes.DropDownItems.Add(ReadOnlyAttributes);
                    }
                }
                object SymlinkFiles = xMenuToolsSettings.GetValue("SymlinkFiles");
                if (SymlinkFiles != null)
                {
                    if (SymlinkFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(SymLink);
                    }
                }
                object TakeOwnershipFiles = xMenuToolsSettings.GetValue("TakeOwnershipFiles");
                if (TakeOwnershipFiles != null)
                {
                    if (TakeOwnershipFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(TakeOwnership);
                    }
                }
                object AttributesShort = xMenuToolsSettings.GetValue("AttributesShort");
                if (AttributesShort != null && isShortcut)
                {
                    if (AttributesShort.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(Attributes);
                    }
                    else
                    {
                        Attributes.Dispose();
                    }
                }
                object OpenNotepadShort = xMenuToolsSettings.GetValue("OpenNotepadShort");
                if (OpenNotepadShort != null && isShortcut)
                {
                    if (OpenNotepadShort.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(OpenNotepad);
                    }
                    else
                    {
                        OpenNotepad.Dispose();
                    }
                }
                object CopyNameShortFiles = xMenuToolsSettings.GetValue("CopyNameShortFiles");
                if (CopyNameShortFiles != null && isShortcut)
                {
                    if (CopyNameShortFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(CopyName);
                    }
                }
                object CopyPathShortFiles = xMenuToolsSettings.GetValue("CopyPathShortFiles");
                if (CopyPathShortFiles != null && isShortcut)
                {
                    if (CopyPathShortFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(CopyPath);
                    }
                }
                object CopyURLShortFiles = xMenuToolsSettings.GetValue("CopyURLShortFiles");
                if (CopyURLShortFiles != null && isShortcut)
                {
                    if (CopyURLShortFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(CopyPathURL);
                    }
                }
                object CopyLONGPathShortFiles = xMenuToolsSettings.GetValue("CopyLONGPathShortFiles");
                if (CopyLONGPathShortFiles != null && isShortcut)
                {
                    if (CopyLONGPathShortFiles.ToString() == "1")
                    {
                        xMenuToolsMenu.DropDownItems.Add(CopyLONGPath);
                    }
                }

                MenuItemDisabler(isShortcut, isExeDllFile);
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\xMenuTools.exe", "\"" + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.Source + Environment.NewLine + ex.GetBaseException() + Environment.NewLine + ex.TargetSite + "\"" + " -catchhandler");
            }
        }
コード例 #11
0
 private void AttributesMenuMethod()
 {
     string[] array = SelectedItemPaths.Cast <string>().ToArray();
     StartProcess.StartInfo(AttributesInfo.GetAssembly.AssemblyInformation("directory") + @"\MenuTools.exe", "\"" + array.ToStringArray(false) + "\" " + "-attributesmenu");
 }