Kernel source code snippets

The following source code snippets show how Google Chrome is installed. If you would like to access the full source code, a download link is provided below.

C# Program.cs

1using System.Diagnostics;
2using System.IO.Compression;
3using ConsoleTables;
4using Spectre.Console;
5using System.Runtime.InteropServices;
6
7namespace Kernel
8{
9    static class Program
10    {
11        private static bool ShouldStopExecution;
12        private static bool Close;
13        private static async Task Main()
14        {
15            const string Installdir = @"C:\Kernel-Setups\";
16            try
17            {
18                while (!ShouldStopExecution)
19                {
20                    AppDomain.CurrentDomain.ProcessExit += (_, _) => { 
21                        ShouldStopExecution = true;
22                        Mods.ClearLine();
23                        if (!Close) {
24                            AppClose.Cleanup();
25                        }
26                    };
27                    Console.CancelKeyPress += (_, e) => { 
28                        e.Cancel = false;
29                        ShouldStopExecution = true;
30                        Mods.ClearLine();
31                        if (!Close) {
32                            AppClose.Cleanup();
33                        }
34                    };
35                    AnsiConsole.Write(new FigletText("Kernel").LeftJustified().Color(Color.Yellow));
36                    Console.WriteLine("Version 1.1.15.0");
37                    Console.Title = "Kernel";
38                    Console.ForegroundColor = ConsoleColor.Yellow;
39                    Console.SetWindowSize(80, 20);
40                    Console.SetBufferSize(200, 10000);
41                    Center.Centerwin();
42                    var Kerneldll = Path.Combine(Environment.CurrentDirectory, "Kernel.dll");
43                    var zipFile = $@"C:\Users\{Environment.UserName}\Downloads\Kernel.zip";
44                    string[] apps =
45                    {
46                        "~Chrome", "~Firefox", "~Brave", "~Opera", "~GX", "~Vivaldi", "~qBittorrent", "~SevenZip", "~PeaZip", "~Discord", 
47                        "~TeamSpeak", "~Zoom", "~Teams", "~Slack", "~Pidgin", "~Trillian", "~Thunderbird", "~Gyazo", "~ShareX", "~Blender", "~Gimp", 
48                        "~Krita", "~Paintdotnet", "~Spotify", "~iTunes", "~VLC", "~Foobar2000", "~Winamp", "~MusicBee", "~Audacity", "~AIMP", 
49                        "~KLiteCodecs", "~Mediamonkey", "OpenHardwareMonitor", "~HWiNFO", "~FurMark","~Steam", "~UbisoftConnect", "~NvidiaDesktop", 
50                        "~NvidiaLaptop", "~LGHub", "~iCUE", "~MSIAfterburner", "~EAapp", "~EpicGames", "~Battlenet", "~PSPlus", "xenia", "RPCS3", 
51                        "~VisualStudio", "~VSCode", "~dotUltimate", "~NoPerMachine", "~NoReSharper", "~NodotTrace", "~NodotCover","~NodotPeek", 
52                        "~NoReSharperCpp", "~NoTeamCity", "~NoRider", "~Rider","~IntellijIDEA", "~JetBrainsToolbox", "~Neovim", "~Notepadpp", 
53                        "~RStudio","~RLanguage", "~Mssql", "~SSMS", "~Mysqlserver", "~Mysqlworkbench", "Cmder", "~FileZilla", "~GitHub", "~Putty", 
54                        "~WinSCP", "~WinMerge", "~Dropbox", "~GoogleDrive", "~OneDrive", "~SugarSync", "~Evernote", "~Everything", "~Revo", "~NVDA", 
55                        "~KeePass2", "~GoogleEarth", "~TeamViewer", "~Wireshark", "~Win10pcap", "~VirtualBox", "~VMware", "~OBS",  "Rufus", "Start11", 
56                        "Redistx64", "Redistx86", "DirectX",
57                            
58                        "`Showall", "`Hideall", "`Hidechat", "`Showchat", "`Hidetaskview", "`Showtaskview", "`Hidewidgets", "`Showwidgets", "`Hidesearch", 
59                        "`Showsearch", "`Leftalign", "`Middlealign", "`Hidebin", "`Showbin", "`Hidebluetooth","`Showbluetooth", "`Smallicons", "`Mediumicons",
60                        "`Disableprecision", "`EnablePrecision", "`Disablenotifications", "`EnableNotifications", "`Smallcursor", "`Uninstallbloatware", 
61                        "`Uninstallonedrive", "`Darkmode", "`Lightmode", "`Showcompactmode", "`Hidecompactmode", "`Hidecheckboxes", "`Showcheckboxes", 
62                        "`Showhiddenitems", "`Hidehiddenitems", "`Showextensions", "`Hideextensions", "`Showfullpath", "`Hidefullpath", "`Hidehome", 
63                        "`Showhome", "`Hiderecentlyusedfiles", "`Showrecentlyusedfiles", "`Showrecyclebinex", "`Hiderecyclebinex", "`Transparency", 
64                        "`Notransparency", "`Showaccentcolorstart", "`Hideaccentcolorstart", "`Showaccentcolorborder", "`Hideaccentcolorborder", "`Blackborders"
65                    };
66                    var directory = Path.GetDirectoryName(zipFile);
67                    const string pattern = "Kernel*.zip";
68                    if (directory != null)
69                    {
70                        var files = Directory.GetFiles(directory, pattern);
71                        var fileInfos = files.Select(f => new FileInfo(f)).ToList();
72                        if (fileInfos.Any())
73                        {
74                            var latestFile = fileInfos.OrderByDescending(f => f.LastWriteTime).First();
75                            zipFile = latestFile.FullName;
76                        }
77                    }
78                    if (Directory.Exists(Installdir)) Directory.Delete(Installdir, true);
79                    if (File.Exists(Kerneldll))
80                    {
81                        var List = await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, "Kernel.dll");
82                        if (apps.Any(n => List.Contains(n)))
83                        {
84                            Directory.CreateDirectory(Installdir);
85                            Console.CursorVisible = false;
86                            Mods.MainDesktop = Mods.GetThreadDesktop((int)Mods.GetCurrentThreadId());
87                            Mods.HiddenDesktop = NewDesktop.CreateDesktop("HiddenDesktop", IntPtr.Zero, IntPtr.Zero, 0, NewDesktop.DESKTOP_CREATEWINDOW | 
88                            NewDesktop.DESKTOP_WRITEOBJECTS | NewDesktop.DESKTOP_ENUMERATE | NewDesktop.DESKTOP_SWITCHDESKTOP, InPtr.Zero);
89                            NewDesktop.SetThreadDesktop(Mods.HiddenDesktop);
90                            await Mods.SevenZip(List);
91                            await Download.Downloads(List);
92                            Mods.ClearLine();
93                            Installs.InstallApps(List);
94                            Installs2.InstallApps(List);
95                            Installs3.InstallApps(List);
96                            Installs4.InstallApps(List);
97                            Installs5.InstallApps(List);
98                           Console.ForegroundColor = ConsoleColor.DarkGreen;
99                           if (List.Contains('~'))
100                           {
101                               Console.WriteLine("");
102                               var TableInstalled = new ConsoleTable("All Application(s) installed");
103                               TableInstalled.Write(Format.Alternative);
104                           }
105                           Console.ForegroundColor = ConsoleColor.Yellow;
106                           await Win11Settings.SetWin11Settings(List);
107                           Mods.RefreshDesktop();
108                           if (List.Contains('`'))
109                           {
110                               var FileExplorer = Process.GetProcessesByName("explorer");
111                               foreach (var explorer in FileExplorer)
112                               {
113                                   explorer.Kill();
114                               }
115                               Thread.Sleep(2000);
116                               if (FileExplorer.Length == 0)
117                               {
118                                   Process.Start("explorer");
119                               }
120                           }
121                           Console.Title = "Kernel";
122                           Directory.Delete(Installdir, true);
123                           Console.ForegroundColor = ConsoleColor.White;
124                           if (List.Contains('`'))
125                           {
126                               Console.WriteLine("");
127                               var Tableapplied = new ConsoleTable("Win 11 change(s) applied");
128                               Tableapplied.Write(Format.Alternative);
129                           }
130                           Console.ForegroundColor = ConsoleColor.DarkGreen;
131                           Console.WriteLine("Press Enter to exit the console window.");
132                           Console.CursorVisible = true;
133                           Close = true;
134                           Console.ReadLine();
135                           ShouldStopExecution = true;
136                           Environment.Exit(0);
137                       }
138                       else
139                       {
140                           var TableInstalled = new ConsoleTable("Kernel.dll doesn't contain any apps to install");
141                           TableInstalled.Write(Format.Alternative);
142                           ConsoleTable.WriteLine("please make sure to extract the Kernel folder from the zip file and re-run Kernel.exe");
143                           ConsoleTable.WriteLine("If this problem persists, please redownload Kernel from https://getkernel.net");
144                           ConsoleTable.WriteLine("Press any key to exit console window");
145                           ConsoleTable.CursorVisible = true;
146                           ConsoleTable.ReadKey();
147                       }
148                   }
149                   else if (File.Exists(zipFile))
150                   {
151                       Directory.CreateDirectory(Installdir);
152                       ZipFile.ExtractToDirectory(zipFile, Installdir);
153                       var List = await File.ReadAllTextAsync(@"C:\Kernel-Setups\Kernel\Kernel.dll");
154                       if (apps.Any(n => List.Contains(n)))
155                       {
156                           Directory.CreateDirectory(Installdir);
157                           Console.CursorVisible = false;
158                            Mods.MainDesktop = Mods.GetThreadDesktop((int)Mods.GetCurrentThreadId());
159                            Mods.HiddenDesktop = NewDesktop.CreateDesktop("HiddenDesktop", IntPtr.Zero, IntPtr.Zero, 0, NewDesktop.DESKTOP_CREATEWINDOW | 
160                            NewDesktop.DESKTOP_WRITEOBJECTS | NewDesktop.DESKTOP_ENUMERATE | NewDesktop.DESKTOP_SWITCHDESKTOP, InPtr.Zero);
161                           NewDesktop.SetThreadDesktop(Mods.HiddenDesktop);
162                           await Mods.SevenZip(List);
163                           await Download.Downloads(List);
164                           Mods.ClearLine();
165                           Installs.InstallApps(List);
166                           Installs2.InstallApps(List);
167                           Installs3.InstallApps(List);
168                           Installs4.InstallApps(List);
169                           Installs5.InstallApps(List);
170                           Console.ForegroundColor = ConsoleColor.DarkGreen;
171                           if (List.Contains('~'))
172                           {
173                               Console.WriteLine("");
174                               var TableInstalled = new ConsoleTable("All Application(s) installed");
175                               TableInstalled.Write(Format.Alternative);
176                           }
177                           Console.ForegroundColor = ConsoleColor.Yellow;
178                           await Win11Settings.SetWin11Settings(List);
179                           Mods.RefreshDesktop();
180                           if (List.Contains('`'))
181                           {
182                               var FileExplorer = Process.GetProcessesByName("explorer");
183                               foreach (var explorer in FileExplorer)
184                               {
185                                   explorer.Kill();
186                               }
187                               Thread.Sleep(2000);
188                               if (FileExplorer.Length == 0)
189                               {
190                                   Process.Start("explorer");
191                               }
192                           }
193                           Console.Title = "Kernel";
194                           Directory.Delete(Installdir, true);
195                           Console.ForegroundColor = ConsoleColor.White;
196                           if (List.Contains('`'))
197                           {
198                               Console.WriteLine("");
199                               var Tableapplied = new ConsoleTable("Win 11 change(s) applied");
200                               Tableapplied.Write(Format.Alternative);
201                           }
202                           Console.ForegroundColor = ConsoleColor.DarkGreen;
203                           Console.WriteLine("Press Enter to exit the console window.");
204                           Console.CursorVisible = true;
205                           Close = true;
206                           Console.ReadLine();
207                           ShouldStopExecution = true;
208                           Environment.Exit(0);
209                       }
210                       else if (!File.Exists(zipFile))
211                       {
212                           Directory.Delete(Installdir, true);
213                           var TableInstalled = new ConsoleTable("Kernel.dll doesn't exist");
214                           TableInstalled.Write(Format.Alternative);
215                           ConsoleTable.WriteLine("please make sure to extract the Kernel folder from the zip file and re-run Kernel.exe");
216                           ConsoleTable.WriteLine("If this problem persists, please redownload Kernel from https://getkernel.net");
217                           ConsoleTable.WriteLine("Press any key to exit console window");
218                           ConsoleTable.CursorVisible = true;
219                           ConsoleTable.ReadKey();
220                       }
221                   }
222               }
223           }
224           catch (Exception ex)
225           {
226               Console.WriteLine(ex.Message);
227               Console.WriteLine(ex.Source);
228               Console.WriteLine(ex.InnerException);
229               Console.WriteLine(ex.Data);
230               Console.WriteLine("An error has occurred, please rerun Kernel.exe, make sure Kernel.dll is in the same directory(folder) as Kernel.dll.");
231               ConsoleTable.WriteLine("If this problem persists, please redownload Kernel from https://getkernel.net");
232               ConsoleTable.WriteLine("Press any key to exit console window");
233               ConsoleTable.CursorVisible = true;
234               ConsoleTable.ReadKey();
235               const string extractPath = $@"C:\Kernel-Setups";
236               if (!Directory.Exists(Installdir))
237               {
238                   Directory.Delete(Installdir, true);
239                   var TableInstalled = new ConsoleTable("Kernel.dll doesn't exist");
240                   TableInstalled.Write(Format.Alternative);
241                   ConsoleTable.WriteLine("please make sure to extract the Kernel folder from the zip file and re-run Kernel.exe");
242                   ConsoleTable.WriteLine("If this problem persists, please redownload Kernel from https://getkernel.net");
243                   ConsoleTable.WriteLine("Press any key to exit console window");
244                   ConsoleTable.CursorVisible = true;
245                   ConsoleTable.ReadKey();
246               }
247               else if (Directory.Exists(extractPath))
248               {
249                   Directory.Delete(Installdir, true);
250                   var TableInstalled = new ConsoleTable("Kernel.dll doesn't exist");
251                   TableInstalled.Write(Format.Alternative);
252                   ConsoleTable.WriteLine("please make sure to extract the Kernel folder from the zip file and re-run Kernel.exe");
253                   ConsoleTable.WriteLine("If this problem persists, please redownload Kernel from https://getkernel.net");
254                   ConsoleTable.WriteLine("Press any key to exit console window");
255                   ConsoleTable.CursorVisible = true;
256                   ConsoleTable.ReadKey();
257               }
258               Console.ReadLine();
259           }
260       }
261   }
262}

C# Downloads.cs

1using System.IO.Compression;
2
3namespace Kernel
4{
5    public static class DownloadsTask
6    {
7        private const string Installdir = @"C:\Kernel-Setups\";
8        //Browsers
9        public static async Task DownloadChrome()
10        {
11            try
12            {
13                 using var response = await new HttpClient().GetAsync("https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C
14                    -AFF1-A69D9E530F96%7D%26iid%3D%7B0DD03CB9-5B8B-A15A-A883-432D88B164CF%7D%26lang%3Den%26browser%3D4%26usagestats
15                    %3D1%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-stable-statsdef_1%26installdatainde%3Dempty/
16                    update2/installers/ChromeSetup.exe", HttpCompletionOption.ResponseHeadersRead);
17                 response.EnsureSuccessStatusCode();
18                 await using var fileStream = new FileStream(Path.Combine($@"{Installdir}", "ChromeSetup.exe"), FileMode.Create);
19                 await using var fileStream = await response.Content.ReadAsStreamAsync();
20                 await stream.CopyToAsync(fileStream, new byte [262114].Length);
21            }
22            catch {  /*ignored*/ }
23        }
24    }
25}

C# Downloading.cs

1namespace Kernel
2{
3    public static class Downloading
4    {
5        public static async Task Downloads(string List)
6        {
7            {
8                var downloads = new List<Task>();
9                var Loading = new Loading();
10                const string Installdir = @"C:\Kernel-Setups\";
11                Console.ForegroundColor = ConsoleColor.DarkGreen;
12                if (List.Contains('~'))
13                {
14                    var TableDownloading = new ConsoleTable("Downloading setup(s)");
15                    TableDownloading.Write(Format.Alternative);
16                }
17                Console.ForegroundColor = ConsoleColor.Yellow; 
18                //Browsers
19                string[] Browsers = { "~Chrome" };
20                if (Browsers.Any(List.Contains))
21                {
22                    Console.ForegroundColor = ConsoleColor.DarkGray;
23                    Console.WriteLine("Setup(s) - Web Browsers");
24                    Console.ForegroundColor = ConsoleColor.Yellow;
25                }
26                if (List.Contains("~Chrome"))
27                {
28                    downloads.Add(Task.Run(async () =>
29                    {
30                        for (var Downloadretry = 0; Downloadretry < 3 && !File.Exists($@"{Installdir}ChromeSetup.exe"); Downloadretry++)
31                        {
32                            await DownloadsTask.DownloadChrome();
33                        }
34                    }));
35                }
36                while (!Task.WaitAll(downloads.ToArray(), 0))
37                {
38                    Downloading.Turn(displayMsg: "Downloading Web Browser Setup(s)", sequenceCode: 0);
39                }
40                Mods.ClearLine();
41                if (List.Contains("~Chrome"))
42                {
43                    Console.WriteLine(await Task.Run(() => File.Exists($@{Installdir}ChromeSetup.exe"))
44                        ? "Download Complete - Chrome"
45                        : "Download Failed - Chrome");
46                }
47                if (Browsers.Any(List.Contains))
48                {
49                    Console.ForegroundColor = ConsoleColor.DarkGreen;
50                    Console.WriteLine("Downloads(s) Complete - Web Browsers");
51                    Console.ForegroundColor = ConsoleColor.Yellow;
52                }
53            }
54        }
55    }
56}

C# Installs.cs

1using System.Diagnostics;
2using ConsoleTables;
3using Microsoft.Win32.RegistryHive;
4using Microsoft.Win32.RegistryKey;
5using Microsoft.Win32.RegistryView;
6
7namespace Kernel
8{
9    public static class Installs
10    {
11        public static void InstallApps(string List)
12        {
13            var Loading = new Loading();
14            const string Installdir = @"C:\Kernel-Setups\";
15            const string Pshortcut = @"C:\Users\Public\Desktop\";
16            var UNshortcut = @"C:\Users\{Environment.UserName}\Desktop\";
17            var ODshortcut = @"C:\Users\{Environment.UserName}\OneDrive\Desktop\";
18            var StartInfo = new NewDesktop.STARTUPINFO
19            {
20                cb = Marshal.SizeOf(typeof(NewDesktop.STARTUPINFO)), lpDesktop = "HiddenDesktop", dwFlags = 0x00000101, wShowWindow = 0
21            };
22            Console.ForegroundColor = ConsoleColor.DarkGreen;
23            if (List.Contains('~'))
24            {
25                Console.WriteLine(); 
26                var.TableInstalling = new ConsoleTable("Installing Application(s)");
27                TableInstalling.Write(Format.Alternative);
28            }
29            Console.ForegroundColor = ConsoleColor.Yellow;
30            //Browsers
31            string[] Browsers = { "~Chrome" };
32            if (Browsers.Any(List.Contains))
33            {
34                Console.ForegroundColor = ConsoleColor.DarkGray;
35                var.TableInstalling = new ConsoleTable("Install(s) - Web Browsers");
36                Console.ForegroundColor = ConsoleColor.Yellow;
37            }
38            if (List.Contains("~Chrome") && File.Exists($"{Installdir}ChromeSetup.exe"))
39            {
40                NewDesktop.CreateProcess(null!, $"{Installdir}ChromeSetup.exe /silent /install", IntPtr.Zero, IntPtr.Zero, true,
41                NewDesktop.CREATE_NEW_CONSOLE | NewDesktop.NORMAL_PRIORITY_CLASS, IntPtr.Zero, null!, ref StartInfo, out var pi);
42            }
43            //Browsers - Waiting for exit
44            if (List.Contains("~Chrome")) && File.Exists($"{Installdir}ChromeSetup.exe"))
45            {
46                var Starttime = DateTime.Now;
47                while ((DateTime.Now - Starttime).TotalSeconds < 90)
48                {
49                    var Setup = Process.GetProcessesByName("ChromeSetup.exe");
50                    Loading.Turn(displayMsg: "Installing Chrome", sequenceCode: 0);
51                    if (Setup.Length == 0)
52                    {  
53                        break;
54                    }
55                    Thread.Sleep(100);
56                }
57                using var Regkey = OpenBaseKey(LocalMachine, Registry64).OpenSubKey("SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\
58                CurrentVersion\\Uninstall\\Google Chrome");
59                for (var Installretry = 0; Installretry < 3 && Regkey == null && !File.Exists(@"C:\Program Files\Google\Chrome\
60                Application\chrome.exe"); Installretry++)
61                {
62                    NewDesktop.CreateProcess(null!, $"{Installdir}ChromeSetup.exe /silent /install", IntPtr.Zero, IntPtr.Zero, true,
63                    NewDesktop.CREATE_NEW_CONSOLE | NewDesktop.NORMAL_PRIORITY_CLASS, IntPtr.Zero, null!, ref StartInfo, out var pi);
64                    var Starttime2 = DateTime.Now;
65                    while ((DateTime.Now - Starttime2).TotalSeconds < 90)
66                    {
67                        var Setup = Process.GetProcessesByName("ChromeSetup.exe");
68                        Loading.Turn(displayMsg: "Installing Chrome", sequenceCode: 0);
69                        if (Setup.Length == 0)
70                        {  
71                            break;
72                        }
73                        Thread.Sleep(100);
74                    }
75                }
76                string[] shortcuts = { $"{Pshortcut}Google Chrome.lnk", $"{UNshortcut}Google Chrome.lnk", $"{ODshortcut}Google Chrome.lnk" };
77                shortcuts.Where(File.Exists).ToList().ForEach(File.Delete);
78                Mods.RefreshDesktop();
79                Mods.ClearLine();
80                Console.WriteLine(Regkey != null || File.Exists(@"C:\Program Files\Google\Chrome\Application\chrome.exe") ? 
81                "Install Complete - Chrome" : "Install Failed - Chrome");
82                }
83            }
84            if (Browsers.Any(List.Contains))
85            {
86                Console.ForegroundColor = ConsoleColor.DarkGreen;
87                Console.WriteLine("Install(s) Complete - Web Browsers");
88                Console.ForegroundColor = ConsoleColor.Yellow;
89            }
90        }
91    }
92}