private void MenuItemDisabler(bool isShortcut, bool isExeDllFile)
        {
            if (isShortcut)
            {
                if (BlockFirewall != null)
                {
                    BlockFirewall.Dispose();
                }
                if (Attributes != null)
                {
                    Attributes.Dispose();
                }
                if (SymLink != null)
                {
                    SymLink.Dispose();
                }
                if (TakeOwnership != null)
                {
                    TakeOwnership.Dispose();
                }
            }
            if (isExeDllFile)
            {
                if (OpenNotepad != null)
                {
                    OpenNotepad.Dispose();
                }
            }
            if (!isExeDllFile)
            {
                if (BlockFirewall != null)
                {
                    BlockFirewall.Dispose();
                }
            }
            bool AllDisabled = true;

            foreach (ToolStripMenuItem item in MenuToolsMenu.DropDownItems)
            {
                if (item != null)
                {
                    AllDisabled = false;
                }
            }
            if (AllDisabled)
            {
                Menu.Dispose();
            }
        }
Beispiel #2
0
        public void Enable(bool Enable)
        {
            RegEdit.SetValue(
                @"HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Windows Search",
                "AllowCortana", Enable ? 0 : 1
                );

            RegEdit.SetValue(
                @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Cortana",
                "IsAvailable", Enable ? 0 : 1
                );

            RegEdit.SetValue(
                @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced",
                "ShowCortanaButton", Enable ? 0 : 1
                );

            //RegEdit.SetValue(
            //    @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search",
            //    "SearchboxTaskbarMode", Enable ? 0 : 1
            //);

            if (Enable)
            {
                /**
                 * Remove Cortana ..
                 */
                Commands.InvokePS("Get-AppxPackage -AllUsers Microsoft.Windows.Cortana | Remove-AppxPackage"); // <= 1909
                Commands.InvokePS("Get-AppxPackage -AllUsers Microsoft.549981C3F5F10 | Remove-AppxPackage");   // >= 2004

                int loop_cortana = 0;

                while (Directory.Exists(@"C:\Windows\SystemApps\Microsoft.Windows.Cortana_cw5n1h2txyewy") && loop_cortana < 20)
                {
                    Process[] searchProcesses = Process.GetProcessesByName("SearchUI");

                    foreach (Process searchProcess in searchProcesses)
                    {
                        try
                        {
                            searchProcess.Kill();
                        }
                        catch (Exception)
                        {
                            Commands.taskkill("SearchUI");
                        }
                    }

                    try
                    {
                        if (loop_cortana % 2 == 0)
                        {
                            TakeOwnership.Folder(@"C:\Windows\SystemApps\Microsoft.Windows.Cortana_cw5n1h2txyewy");
                        }

                        Dir.DeleteDir(@"C:\Windows\SystemApps\Microsoft.Windows.Cortana_cw5n1h2txyewy");
                    }
                    catch (Exception)
                    {
                    }

                    loop_cortana++;
                }

                if (loop_cortana >= 20)
                {
                    Console.WriteLine("Failed to properly disable \"Cortana\"!");
                }

                /**
                 * Remove SearchApp ..
                 */
                Commands.InvokePS("Get-AppxPackage -AllUsers Microsoft.Windows.Search | Remove-AppxPackage");

                int loop_searchapp = 0;

                while (Directory.Exists(@"Microsoft.Windows.Search_cw5n1h2txyewy") && loop_searchapp < 20)
                {
                    Process[] searchProcesses = Process.GetProcessesByName("SearchApp");

                    foreach (Process searchProcess in searchProcesses)
                    {
                        try
                        {
                            searchProcess.Kill();
                        }
                        catch (Exception)
                        {
                            Commands.taskkill("SearchApp");
                        }
                    }

                    try
                    {
                        if (loop_searchapp % 2 == 0)
                        {
                            TakeOwnership.Folder(@"Microsoft.Windows.Search_cw5n1h2txyewy");
                        }

                        Dir.DeleteDir(@"Microsoft.Windows.Search_cw5n1h2txyewy");
                    }
                    catch (Exception)
                    {
                    }

                    loop_searchapp++;
                }

                if (loop_searchapp >= 20)
                {
                    Console.WriteLine("Failed to properly disable \"Search App\"!");
                }
            }
            else // if !Enable
            {
                dynamic WinVer = Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion", "ReleaseId", 0);

                /**
                 * Re-enable Cortana ..
                 */
                try
                {
                    if ((int)WinVer <= 1909)
                    {
                        Commands.InvokePS("Get-AppxPackage -AllUsers Microsoft.Windows.Cortana | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register \"$($_.InstallLocation)\\AppXManifest.xml\"}"); // <= 1909
                    }
                    else
                    {
                        Commands.InvokePS("Get-AppxPackage -AllUsers Microsoft.549981C3F5F10 | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register \"$($_.InstallLocation)\\AppXManifest.xml\"}");   // >= 2004
                    }
                }
                catch (Exception) { }

                /**
                 * Re-enable SearchApp ..
                 */
                try
                {
                    Commands.InvokePS("Get-AppxPackage -AllUsers Microsoft.Windows.Search | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register \"$($_.InstallLocation)\\AppXManifest.xml\"}");
                }
                catch (Exception) { }
            }
        }