public async Task SendInformationAsync(DiagnosticsInformation information) { var hostname = configuration.GetDiagnosticsServerHostname(); var port = configuration.GetDiagnosticsServerPort(); if (hostname != null && port.HasValue) { using (var client = new TcpClient()) { try { await client.ConnectAsync(hostname, port.Value); using (var stream = new StreamWriter(client.GetStream())) { await stream.WriteAsync(JsonConvert.SerializeObject(information)); await stream.FlushAsync(); } } catch (Exception) { // ignored } } } }
private string FormatUnwrittenMessages(DiagnosticsInformation information) { var sb = new StringBuilder(); foreach (var timing in information.EventTimings) { sb.AppendLine(FormatMessage(timing)); } return(sb.ToString()); }
protected override InformationBar GetInformationBar() { if (Hive != RegistryHive.LocalMachine || DiagnosticsInformation.GetTokenElevationType() == TokenElevationType.Full) { return(null); } var bar = new InformationBar(); bar.Guid = _adminMessageGuid; bar.Message = "You must be running with full priviledges to change anything here"; return(bar); }
protected async override void OnDragDropTarget(DragDropTargetEventArgs e) { e.Effect = DragDropEffects.Copy; if (e.Type == DragDropTargetEventType.DragDrop) { // you can use other formats but this one is the only one that contains PIDLs var list = string.Join(Environment.NewLine, e.DataObject.ItemsIdLists.Select(id => id.GetName(Core.WindowsShell.SIGDN.SIGDN_NORMALDISPLAY))); await WindowsUtilities.DoModelessAsync(() => { MessageBox.Show(null, "UAC level is " + DiagnosticsInformation.GetTokenElevationType(), "Registry Folder"); }); } }
public Task SendInformationAsync(DiagnosticsInformation information) { var messages = FormatUnwrittenMessages(information); lock (locker) { if (!File.Exists(logFilePath)) { messages = $@"{"Event Name",-70}{"Duration [ms]",15}{"Total [ms]",15} {new string('-', 70 + 15 + 15)} {messages}"; } File.AppendAllText(logFilePath, messages); } return(TaskUtils.GetCompletedTask()); }
static void Main() { const string testProperty = "ShellBoost.Samples.LocalFolder.IconUI"; string already = PropertySystem.GetPropertyDescription(testProperty, false) != null ? " (note: they are already registered)." : "."; Console.WriteLine("ShellBoost Samples - Local Folder - Copyright (C) 2017-" + DateTime.Now.Year + " Aelyo Softworks. All rights reserved."); Console.WriteLine("ShellBoost Runtime Version " + typeof(ShellContext).Assembly.GetInformationalVersion()); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine(); Console.WriteLine(" '1' Register the native proxy, run this sample, and unregister on exit."); Console.WriteLine(" '2' Register the native proxy."); Console.WriteLine(" '3' Run this sample (the native proxy will need to be registered somehow for Explorer to display something)."); Console.WriteLine(" '4' Unregister the native proxy."); Console.WriteLine(" '5' Restart Windows Explorer."); Console.WriteLine(" '6' Register Custom Properties for this sample" + already + (DiagnosticsInformation.GetTokenElevationType() == TokenElevationType.Full ? string.Empty : " You need to restart as admin.")); Console.WriteLine(" '7' Unregister Custom Properties for this sample." + (DiagnosticsInformation.GetTokenElevationType() == TokenElevationType.Full ? string.Empty : " You need to restart as admin.")); Console.WriteLine(); Console.WriteLine(" Any other key will exit."); Console.WriteLine(); string schemaLocation = new ShellFolderConfiguration().ExtractAssemblyResource(typeof(Program).Namespace + ".Resources.LocalFolder.propdesc"); do { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Escape) { return; } switch (key.KeyChar) { case '1': Run(true); ShellFolderServer.UnregisterNativeDll(RegistrationMode.User); return; case '2': ShellFolderServer.RegisterNativeDll(RegistrationMode.User); Console.WriteLine("Registered"); break; case '3': Run(false); return; case '4': ShellFolderServer.UnregisterNativeDll(RegistrationMode.User); Console.WriteLine("Unregistered"); break; case '5': var rm = new RestartManager(); rm.RestartExplorerProcesses((state) => { Console.WriteLine("Explorer was stopped. Press any key to restart it ..."); Console.ReadKey(true); }, false, out Exception error); if (error != null) { Console.WriteLine("An error has occurred in restart manager: " + error); } break; case '6': try { PropertySystem.RegisterPropertySchema(schemaLocation); Console.WriteLine("Properties are registered. Schema location is: " + schemaLocation); } catch (Exception e) { Console.WriteLine("Properties cannot be registered: " + e.Message); } if (PropertySystem.GetPropertyDescription(testProperty, false) != null) { Console.WriteLine("Properties can be successfully retrieved from database."); } break; case '7': try { PropertySystem.UnregisterPropertySchema(schemaLocation); Console.WriteLine("Properties are unregistered."); } catch (Exception e) { Console.WriteLine("Properties cannot be unregistered: " + e.Message); } if (PropertySystem.GetPropertyDescription(testProperty, false) != null) { Console.WriteLine("Properties can be successfully retrieved from database. They should not."); } break; } }while (true); }
static void Main() { Initializer = new callback.CBFSShell.Cbshellboost(); Initializer.ProductGUID = ProductID; // this source is used by two projects: Overview (.NET Framework) and CoreOverview (.NET Core 3+) Console.WriteLine("ShellBoost Samples - " + (Installer.IsNetCore ? "Core" : null) + "Overview - " + (IntPtr.Size == 4 ? "32" : "64") + "-bit - Copyright (C) 2021-" + DateTime.Now.Year + " Callback Technologies, Inc. All rights reserved."); Console.WriteLine("ShellBoost Runtime Version " + typeof(ShellContext).Assembly.GetInformationalVersion()); Console.WriteLine(); // use "ShellBoost.Samples.Overview.exe /mode:machine" to switch to machine registration. var regMode = CommandLine.GetArgument <RegistrationMode>("mode"); if (regMode == RegistrationMode.None) { regMode = RegistrationMode.User; } if (regMode == RegistrationMode.User && !DiagnosticsInformation.IsUACEnabled()) { Console.WriteLine("UAC is disabled on this sytem, per-user registration is not supported. Retry with /mode:machine argument."); return; } Console.WriteLine("RegistrationMode: " + regMode); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine(); Console.WriteLine(" '1' Install the native proxy, run this sample, and uninstall on exit."); Console.WriteLine(" '2' Install the native proxy."); Console.WriteLine(" '3' Run this sample (the native proxy will need to be registered somehow for Explorer to display something)."); Console.WriteLine(" '4' Uninstall the native proxy."); Console.WriteLine(); Console.WriteLine(" Any other key will exit."); Console.WriteLine(); var key = Console.ReadKey(true); while (true) { switch (key.KeyChar) { case '1': Register(regMode == RegistrationMode.User); // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods) Initializer.Initialize(); key = Run(); Initializer.PerUserInstallation = regMode == RegistrationMode.User; Initializer.Uninstall(); break; case '2': Register(regMode == RegistrationMode.User); key = Console.ReadKey(true); break; case '3': // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods) Initializer.Initialize(); key = Run(); break; case '4': Initializer.PerUserInstallation = regMode == RegistrationMode.User; try { Initializer.Uninstall(); Console.WriteLine("Unregistered"); } catch (Exception ex) { Console.WriteLine("EXCEPTION: "); Console.WriteLine(ex.Message); } key = Console.ReadKey(true); break; default: Console.WriteLine("Done"); return; } } }
static void Main() { Initializer = new callback.CBFSShell.Cbshellboost(); Initializer.ProductGUID = ProductID; const string testProperty = "ShellBoost.Samples.LocalFolder.IconUI"; string already = PropertySystem.GetPropertyDescription(testProperty, false) != null ? " (note: they are already registered)." : "."; Console.WriteLine("CBFS Shell Samples - Local Folder - Copyright (C) 2021-2022 Callback Technologies, Inc. All rights reserved."); Console.WriteLine("CBFS Shell Runtime Version " + typeof(ShellContext).Assembly.GetInformationalVersion()); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine(); Console.WriteLine(" '1' Register the native proxy, run this sample, and unregister on exit."); Console.WriteLine(" '2' Register the native proxy."); Console.WriteLine(" '3' Run this sample (the native proxy will need to be registered somehow for Explorer to display something)."); Console.WriteLine(" '4' Unregister the native proxy."); Console.WriteLine(" '5' Restart Windows Explorer."); Console.WriteLine(" '6' Register Custom Properties for this sample" + already + (DiagnosticsInformation.GetTokenElevationType() == TokenElevationType.Full ? string.Empty : " You need to restart as admin.")); Console.WriteLine(" '7' Unregister Custom Properties for this sample." + (DiagnosticsInformation.GetTokenElevationType() == TokenElevationType.Full ? string.Empty : " You need to restart as admin.")); Console.WriteLine(); Console.WriteLine(" Any other key will exit."); Console.WriteLine(); string schemaLocation = new ShellFolderConfiguration().ExtractAssemblyResource(typeof(Program).Namespace + ".Resources.LocalFolder.propdesc"); do { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Escape) { return; } switch (key.KeyChar) { case '1': Register(true); // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods) Initializer.Initialize(); Run(); Initializer.PerUserInstallation = true; Initializer.Uninstall(); return; case '2': Register(true); break; case '3': // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods) Initializer.Initialize(); Run(); return; case '4': Initializer.PerUserInstallation = true; try { Initializer.Uninstall(); Console.WriteLine("Unregistered"); } catch (Exception ex) { Console.WriteLine("EXCEPTION: "); Console.WriteLine(ex.Message); } break; case '5': var rm = new RestartManager(); rm.RestartExplorerProcesses((state) => { Console.WriteLine("Explorer was stopped. Press any key to restart it ..."); Console.ReadKey(true); }, false, out Exception error); if (error != null) { Console.WriteLine("An error has occurred in restart manager: " + error); } break; case '6': try { PropertySystem.RegisterPropertySchema(schemaLocation); Console.WriteLine("Properties are registered. Schema location is: " + schemaLocation); } catch (Exception e) { Console.WriteLine("Properties cannot be registered: " + e.Message); } if (PropertySystem.GetPropertyDescription(testProperty, false) != null) { Console.WriteLine("Properties can be successfully retrieved from database."); } break; case '7': try { PropertySystem.UnregisterPropertySchema(schemaLocation); Console.WriteLine("Properties are unregistered."); } catch (Exception e) { Console.WriteLine("Properties cannot be unregistered: " + e.Message); } if (PropertySystem.GetPropertyDescription(testProperty, false) != null) { Console.WriteLine("Properties can be successfully retrieved from database. They should not."); } break; } }while (true); }
static void Main(string[] args) { Console.WriteLine("ShellBoost Samples - Registry Folder - Copyright (C) 2017-" + DateTime.Now.Year + " Aelyo Softworks. All rights reserved."); Console.WriteLine("ShellBoost Runtime Version " + typeof(ShellContext).Assembly.GetInformationalVersion()); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine(); Console.WriteLine(" '1' Register the native proxy, run this sample, and unregister on exit."); Console.WriteLine(" '2' Register the native proxy."); Console.WriteLine(" '3' Run this sample (the native proxy will need to be registered somehow for Explorer to display something)."); Console.WriteLine(" '4' Unregister the native proxy."); Console.WriteLine(" '5' Restart Windows Explorer."); Console.WriteLine(" '6' Register Custom Properties for this sample." + (DiagnosticsInformation.GetTokenElevationType() == TokenElevationType.Full ? string.Empty : " You need to restart as admin.")); Console.WriteLine(); Console.WriteLine(" Any other key will exit."); Console.WriteLine(); var key = Console.ReadKey(true); switch (key.KeyChar) { case '1': Run(true); ShellFolderServer.UnregisterNativeDll(RegistrationMode.User); break; case '2': ShellFolderServer.RegisterNativeDll(RegistrationMode.User); Console.WriteLine("Registered"); break; case '3': Run(false); break; case '4': ShellFolderServer.UnregisterNativeDll(RegistrationMode.User); Console.WriteLine("Unregistered"); break; case '5': var rm = new RestartManager(); rm.RestartExplorerProcesses((state) => { Console.WriteLine("Explorer was stopped. Press any key to restart it ..."); Console.ReadKey(true); }, false, out Exception error); if (error != null) { Console.WriteLine("An error has occurred in restart manager: " + error); } break; case '6': string location = new ShellFolderConfiguration().ExtractAssemblyResource(typeof(Program).Namespace + ".Resources.RegistryFolder.propdesc"); try { PropertySystem.RegisterPropertySchema(location); } catch (Exception e) { Console.WriteLine("Properties cannot be registered: " + e.Message); break; } Console.WriteLine("Properties are registered. Schema location: " + location); break; } }
protected override async void HandleInformationBarMenu(InformationBar bar, IntPtr hwndOwner, int id) { if (id == 1) // first item has id 1, etc. { await WindowsUtilities.DoModelessAsync(() => { System.Windows.Forms.MessageBox.Show(new Win32Window(hwndOwner), "UAC level is " + DiagnosticsInformation.GetTokenElevationType(), "Registry Folder"); }); return; } }
private string GetDebugInformation() => DiagnosticsInformation.Serialize(null);
static void Main(string[] args) { Initializer = new callback.CBFSShell.Cbshellboost(); Initializer.ProductGUID = ProductID; Console.WriteLine("ShellBoost Samples - Registry Folder - Copyright (C) 2021-2022 Callback Technologies, Inc. All rights reserved."); Console.WriteLine("ShellBoost Runtime Version " + typeof(ShellContext).Assembly.GetInformationalVersion()); Console.WriteLine(); Console.WriteLine("Press a key:"); Console.WriteLine(); Console.WriteLine(" '0' Register Custom Properties for this sample." + (DiagnosticsInformation.GetTokenElevationType() == TokenElevationType.Full ? string.Empty : " You need to restart as admin.")); Console.WriteLine(" '1' Register the native proxy, run this sample, and unregister on exit."); Console.WriteLine(" '2' Register the native proxy."); Console.WriteLine(" '3' Run this sample (the native proxy will need to be registered somehow for Explorer to display something)."); Console.WriteLine(" '4' Unregister the native proxy."); Console.WriteLine(" '5' Restart Windows Explorer."); Console.WriteLine(); Console.WriteLine(" Any other key will exit."); Console.WriteLine(); var key = Console.ReadKey(true); switch (key.KeyChar) { case '1': Register(true); // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods) Initializer.Initialize(); Run(); Initializer.PerUserInstallation = true; Initializer.Uninstall(); return; case '2': Register(true); break; case '3': // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods) Initializer.Initialize(); Run(); return; case '4': Initializer.PerUserInstallation = true; try { Initializer.Uninstall(); Console.WriteLine("Unregistered"); } catch (Exception ex) { Console.WriteLine("EXCEPTION: "); Console.WriteLine(ex.Message); } break; case '5': var rm = new RestartManager(); rm.RestartExplorerProcesses((state) => { Console.WriteLine("Explorer was stopped. Press any key to restart it ..."); Console.ReadKey(true); }, false, out Exception error); if (error != null) { Console.WriteLine("An error has occurred in restart manager: " + error); } break; case '0': string location = new ShellFolderConfiguration().ExtractAssemblyResource(typeof(registryfolderDemo).Namespace + ".RegistryFolder.propdesc"); try { PropertySystem.RegisterPropertySchema(location); } catch (Exception e) { Console.WriteLine("Properties cannot be registered: " + e.Message); break; } Console.WriteLine("Properties are registered. Schema location: " + location); break; } }