11using System ;
22using System . Diagnostics ;
3+ using System . Security . Principal ;
4+ using System . Threading ;
5+ using Microsoft . Win32 ;
36
47namespace DisableSearchBoxSuggestions
58{
@@ -29,9 +32,18 @@ Disable Search Box Suggestions
2932 by KilLo
3033 github.com/KilLo445" ;
3134
35+ public static bool ExplorerRunning = true ;
36+
37+ public static bool IsAdministrator ( )
38+ {
39+ var identity = WindowsIdentity . GetCurrent ( ) ;
40+ var principal = new WindowsPrincipal ( identity ) ;
41+ return principal . IsInRole ( WindowsBuiltInRole . Administrator ) ;
42+ }
43+
3244 static void Main ( string [ ] args )
3345 {
34- Console . Title = "Disable Search Box Suggestions" ;
46+ Console . Title = "Disable Search Box Suggestions by KilLo " ;
3547
3648 Console . WriteLine ( asciiArt ) ;
3749 Console . WriteLine ( ) ;
@@ -41,17 +53,145 @@ static void Main(string[] args)
4153 Console . WriteLine ( ) ;
4254 Console . WriteLine ( "[1] Disable Search Box Suggestions" ) ;
4355 Console . WriteLine ( "[2] Enable Search Box Suggestions" ) ;
44- Console . WriteLine ( "[3] Open DSBS GitHub" ) ;
56+ Console . WriteLine ( "[3] About DSBS" ) ;
57+ Console . WriteLine ( "[4] Open DSBS GitHub" ) ;
4558 Console . WriteLine ( ) ;
4659 Console . Write ( "Enter choice: " ) ;
4760 string userInput = Console . ReadLine ( ) ;
4861 Console . WriteLine ( ) ;
49- if ( userInput == "1" ) { }
50- if ( userInput == "2" ) { }
51- if ( userInput == "3" ) { Console . WriteLine ( "Opening GitHub link..." ) ; Process . Start ( githubLink ) ; }
62+ Console . WriteLine ( "--------------------------------------------------" ) ;
63+ Console . WriteLine ( ) ;
64+ if ( userInput == "1" ) { DSBS ( ) ; PressAnyKeyToExit ( ) ; }
65+ if ( userInput == "2" ) { ESBS ( ) ; PressAnyKeyToExit ( ) ; }
66+ if ( userInput == "3" ) { AboutDSBS ( ) ; PressAnyKeyToExit ( ) ; }
67+ if ( userInput == "4" ) { Console . WriteLine ( "Opening GitHub link..." ) ; Process . Start ( githubLink ) ; }
68+ if ( userInput != "1" || userInput != "2" || userInput != "3" || userInput != "4" ) { Console . WriteLine ( "Unknown command..." ) ; PressAnyKeyToExit ( ) ; }
69+ PressAnyKeyToExit ( ) ;
70+ }
71+
72+ public static void DSBS ( )
73+ {
74+ Console . WriteLine ( "Checking for permission..." ) ;
75+ Thread . Sleep ( 100 ) ;
76+ if ( IsAdministrator ( ) ) { Console . WriteLine ( "Permission granted!" ) ; }
77+ else { Console . WriteLine ( "No permission, please run as administrator and try again!" ) ; PressAnyKeyToExit ( ) ; }
78+ Thread . Sleep ( 100 ) ;
79+ Console . WriteLine ( ) ;
80+ Console . WriteLine ( "Checking for registry key HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Policies\\ Microsoft\\ Windows\\ Explorer..." ) ;
81+ Thread . Sleep ( 100 ) ;
82+ RegistryKey keyExp = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Policies\Microsoft\Windows\Explorer" , true ) ;
83+ if ( keyExp == null )
84+ {
85+ Console . WriteLine ( "Key does not exist! Creating it..." ) ;
86+ Thread . Sleep ( 100 ) ;
87+ try
88+ {
89+ RegistryKey keyWin = Registry . LocalMachine . CreateSubKey ( @"SOFTWARE\Policies\Microsoft\Windows\Explorer" ) ;
90+ Console . WriteLine ( "Key created! Closing registry..." ) ;
91+ keyWin . Close ( ) ;
92+ }
93+ catch ( Exception e ) { ExceptionMSG ( e ) ; }
94+ }
95+ else { Console . WriteLine ( "Key found!" ) ; }
96+ try
97+ {
98+ Thread . Sleep ( 100 ) ;
99+ Console . WriteLine ( "Creating DWORD value DisableSearchBoxSuggestions..." ) ;
100+ keyExp . SetValue ( "DisableSearchBoxSuggestions" , "1" , RegistryValueKind . DWord ) ;
101+ Thread . Sleep ( 100 ) ;
102+ Console . WriteLine ( "Value created!" ) ;
103+ }
104+ catch ( Exception e ) { ExceptionMSG ( e ) ; }
105+ Thread . Sleep ( 100 ) ;
106+ Console . WriteLine ( "Closing registry..." ) ;
107+ keyExp . Close ( ) ;
108+ Thread . Sleep ( 100 ) ;
109+ RestartExplorer ( ) ;
110+ return ;
111+ }
112+
113+ public static void ESBS ( )
114+ {
115+ Console . WriteLine ( "Checking for permission..." ) ;
116+ Thread . Sleep ( 100 ) ;
117+ if ( IsAdministrator ( ) ) { Console . WriteLine ( "Permission granted!" ) ; }
118+ else { Console . WriteLine ( "No permission, please run as administrator and try again!" ) ; PressAnyKeyToExit ( ) ; }
119+ Console . WriteLine ( ) ;
120+ Thread . Sleep ( 100 ) ;
121+ Console . WriteLine ( "Checking for registry key HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Policies\\ Microsoft\\ Windows\\ Explorer..." ) ;
122+ RegistryKey keyExp = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Policies\Microsoft\Windows\Explorer" , true ) ;
123+ if ( keyExp == null ) { Console . WriteLine ( "Search box suggestions are not enabled." ) ; }
124+ else { Console . WriteLine ( "Key found!" ) ; }
125+ try
126+ {
127+ Thread . Sleep ( 100 ) ;
128+ if ( Registry . GetValue ( "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Policies\\ Microsoft\\ Windows\\ Explorer" , "DisableSearchBoxSuggestions" , null ) == null ) { Console . WriteLine ( "Search box suggestions are not enabled." ) ; }
129+ else
130+ {
131+ Console . WriteLine ( "Deleting DWORD value DisableSearchBoxSuggestions..." ) ;
132+ keyExp . DeleteValue ( "DisableSearchBoxSuggestions" ) ;
133+ Thread . Sleep ( 100 ) ;
134+ Console . WriteLine ( "Value deleted!" ) ;
135+ }
136+ }
137+ catch ( Exception e ) { ExceptionMSG ( e ) ; }
138+ Thread . Sleep ( 100 ) ;
139+ Console . WriteLine ( "Closing registry..." ) ;
140+ keyExp . Close ( ) ;
141+ Thread . Sleep ( 100 ) ;
142+ RestartExplorer ( ) ;
143+ return ;
144+ }
145+
146+ public static void RestartExplorer ( )
147+ {
148+ Console . WriteLine ( "Restarting explorer..." ) ;
149+ if ( Process . GetProcessesByName ( "explorer" ) . Length > 0 )
150+ {
151+ ExplorerRunning = true ;
152+ try
153+ {
154+ Process [ ] explorer = Process . GetProcessesByName ( "explorer" ) ;
155+ foreach ( Process process in explorer ) { process . Kill ( ) ; ExplorerRunning = false ; }
156+ }
157+ catch ( Exception e ) { ExceptionMSG ( e ) ; }
158+ }
159+ Thread . Sleep ( 500 ) ;
160+ if ( Process . GetProcessesByName ( "explorer" ) . Length < 0 )
161+ {
162+ try
163+ {
164+ Process . Start ( "explorer" ) ;
165+ }
166+ catch ( Exception e ) { ExceptionMSG ( e ) ; }
167+ }
168+ while ( ! ExplorerRunning )
169+ {
170+ Console . WriteLine ( "Waiting for explorer..." ) ;
171+ if ( Process . GetProcessesByName ( "explorer" ) . Length > 0 ) { ExplorerRunning = true ; }
172+ else { ExplorerRunning = false ; }
173+ Thread . Sleep ( 500 ) ;
174+ }
175+ Thread . Sleep ( 100 ) ;
176+ if ( ExplorerRunning ) { Console . WriteLine ( "Explorer running!" ) ; }
177+ return ;
178+ }
179+
180+ public static void AboutDSBS ( ) { Console . WriteLine ( "DisableSearchBoxSuggestions, or DSBS is a simple tool created by KilLo (github.com/KilLo445) that disables the annoying web-searches and Copilot in the Windows 11 Start Menu, allowing you to only search for files and run commands." ) ; }
181+
182+ public static void ExceptionMSG ( Exception ex )
183+ {
184+ Console . WriteLine ( ) ;
185+ Console . WriteLine ( "An error occured..." ) ;
186+ Console . WriteLine ( $ "{ ex } ") ;
187+ PressAnyKeyToExit ( ) ;
188+ }
189+
190+ public static void PressAnyKeyToExit ( )
191+ {
52192 Console . WriteLine ( ) ;
53- Console . WriteLine ( "Press any key to exit..." ) ;
54- Console . ReadLine ( ) ;
193+ Console . Write ( "Press any key to exit..." ) ;
194+ Console . ReadKey ( ) ;
55195 Environment . Exit ( 0 ) ;
56196 }
57197 }
0 commit comments