Exemplo n.º 1
0
        private void WebDriveThread(object state)
        {
            do
            {
                try
                {
                    // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods)
                    Initializer.Initialize();

                    using (var server = new WebShellFolderServer())
                    {
                        var config = new ShellFolderConfiguration();
                        config.Logger = new Logger(this);

                        server.Start(config);
                        AppendText("Started listening on proxy id " + ShellFolderServer.ProxyId);

                        if (ShellFolderServer.LocationFolderId != Guid.Empty)
                        {
                            Dispatcher.BeginInvoke(() =>
                            {
                                Open.IsEnabled = true;
                            });
                        }
                        _serverStopEvent.WaitOne();
                        return;
                    }
                }
                catch (Exception e)
                {
                    AppendText(e.Message);
                    Thread.Sleep(1000);
                }
            }while (true);
        }
Exemplo n.º 2
0
        private void WebDriveThread(object state)
        {
            do
            {
                try
                {
                    using (var server = new WebShellFolderServer())
                    {
                        var config = new ShellFolderConfiguration();
                        config.Logger = new Logger(this);

                        server.Start(config);
                        AppendText("Started listening on proxy id " + ShellFolderServer.ProxyId);

                        if (ShellFolderServer.LocationFolderId != Guid.Empty)
                        {
                            Dispatcher.BeginInvoke(() =>
                            {
                                Open.IsEnabled = true;
                            });
                        }
                        _serverStopEvent.WaitOne();
                        return;
                    }
                }
                catch (Exception e)
                {
                    AppendText(e.Message);
                    Thread.Sleep(1000);
                }
            }while (true);
        }
Exemplo n.º 3
0
        static void Run(bool register)
        {
            using (var server = new PhysicalOverviewShellFolderServer())
            {
                var config = new ShellFolderConfiguration();
                if (register)
                {
                    config.NativeDllRegistration = RegistrationMode.User;
                }

#if DEBUG
                config.Logger = new Core.Utilities.ConsoleLogger();
#endif
                server.Licensing += OnLicensing;

                server.Start(config);
                Console.WriteLine("Folder id " + ShellFolderServer.FolderId);
                Console.WriteLine("Started listening on proxy id " + ShellFolderServer.ProxyId + ". Press ESC key to stop serving folders.");
                Console.WriteLine("If you open Windows Explorer and have registered, you should now see the extension.");
                while (Console.ReadKey(true).Key != ConsoleKey.Escape)
                {
                }
                Console.WriteLine("Stopped");
            }
        }
Exemplo n.º 4
0
        static void Run()
        {
            // TODO: change the root folder here
            using (var server = new MirrorFolderServer(@"c:\"))
            {
                var config = new ShellFolderConfiguration();


#if DEBUG
                config.Logger = new ShellBoost.Core.Utilities.ConsoleLogger();
#endif

                server.Start(config);

                Console.WriteLine("Folder id " + ShellFolderServer.FolderId);
                Console.WriteLine("Trace id " + ShellFolderServer.TraceId);
                Console.WriteLine("Started listening on proxy id " + ShellFolderServer.ProxyId + ". Press ESC key to stop serving folders.");
                Console.WriteLine("If you open Windows Explorer, you should now see the extension.");
                ConsoleKeyInfo key;
                do
                {
                    key = Console.ReadKey(true);
                    switch (key.Key)
                    {
                    case ConsoleKey.Escape:
                        break;

                    case ConsoleKey.C:
                        Console.Clear();
                        break;
                    }
                } while (key.Key != ConsoleKey.Escape);
                Console.WriteLine("Stopped");
            }
        }
Exemplo n.º 5
0
        private void DriveThread(object state)
        {
            var logger = new Logger(this);
            var config = new ShellFolderConfiguration();

            config.Logger = logger;

            ShellFolderServer.RegisterNativeDll(RegistrationMode.User);
            ShellUtilities.RefreshShellViews();

            do
            {
                try
                {
                    using (_server = new OnDemandShellFolderServer(new DirectoryInfo(DriveService.AllRootsPath)))
                    {
                        _server.Start(config);
                        AppendText("Started listening on proxy id " + ShellFolderServer.ProxyId);
                        _serverStopEvent.WaitOne();
                        _server = null;
                        return;
                    }
                }
                catch (Exception e)
                {
                    logger.Log(TraceLevel.Error, "An error occurred: " + e);
                    Thread.Sleep(1000);
                }
            }while (true);
        }
Exemplo n.º 6
0
        private void CommonStart(string ipcFormat = null)
        {
            _server?.Stop();

            Initializer             = new callback.CBFSShell.Cbshellboost();
            Initializer.ProductGUID = ProductID;

            Register();

            // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods)
            Initializer.Initialize();

            _server = new OverviewShellFolderServer();
            var config = new ShellFolderConfiguration();

            // we're not impersonating client
            config.ImpersonateClient = false;

            // this will fix an endpoint for clients connecting to a service:
            // they *must* install ShellBoost with "ShellBoost.Samples.FolderService.ShellFolderService" as IpcFormat.
            //
            // clients from interactive run (console) don't need that.
            config.IpcFormat = ipcFormat;

            _server.Start(config);
        }
Exemplo n.º 7
0
        static void Run(bool register)
        {
#if NET
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

#if DEBUG
            // added for debugging purposes
            TaskScheduler.UnobservedTaskException += OnTaskSchedulerUnobservedTaskException;
#endif

            using (var server = WebShellFolderServer.Current)
            {
                var config = new ShellFolderConfiguration();
                if (register)
                {
                    config.NativeDllRegistration = RegistrationMode.User;
                }

#if DEBUG
                config.Logger = new Core.Utilities.ConsoleLogger {
                    AddCounter = true
                };
#endif

                server.Licensing += OnLicensing;
                server.Start(config);

                Console.WriteLine("Folder id " + ShellFolderServer.FolderId);
                Console.WriteLine("Trace id " + ShellFolderServer.TraceId);
                Console.WriteLine("Started listening on proxy id " + ShellFolderServer.ProxyId + ". Press ESC key to stop serving folders.");
                Console.WriteLine("If you open Windows Explorer and have registered, you should now see the extension.");
                ConsoleKeyInfo key;
                do
                {
                    key = Console.ReadKey(true);
                    switch (key.Key)
                    {
                    case ConsoleKey.Escape:
                        break;

                    case ConsoleKey.C:
                        Console.Clear();
                        break;

                    case ConsoleKey.S:
                        server.LocalEvents.Synchronize();
                        break;
                    }
                } while (key.Key != ConsoleKey.Escape);
                Console.WriteLine("Stopped");
            }
        }
        private void CommonStart(string ipcFormat = null)
        {
            _server?.Stop();
            _server = new OverviewShellFolderServer();
            var config = new ShellFolderConfiguration();

            // we're not impersonating client
            config.ImpersonateClient = false;

            // this will fix an endpoint for clients connecting to a service:
            // they *must* register with "ShellBoost.Samples.FolderService.ShellFolderService" as IpcFormat.
            //
            // clients from interactive run (console) don't need that.
            config.IpcFormat = ipcFormat;

            config.NativeDllRegistration = RegistrationMode.User;
            _server.Start(config);
        }
Exemplo n.º 9
0
        static void Run()
        {
            using (var server = new DeviceManagerFolderServer())
            {
                var config = new ShellFolderConfiguration();
#if DEBUG
                config.Logger = new ConsoleLogger();
#endif

                server.Start(config);
                Console.WriteLine("Started listening on proxy id " + ShellFolderServer.ProxyId + ". Press ESC key to stop serving folders.");
                Console.WriteLine("If you open Windows Explorer and have registered, you should now see the extension.");
                while (Console.ReadKey(true).Key != ConsoleKey.Escape)
                {
                }
                Console.WriteLine("Stopped");
            }
        }
Exemplo n.º 10
0
        static void Run(bool register)
        {
            var info = new DirectoryInfo(Path.GetFullPath("Data"));

            if (!info.Exists)
            {
                info.Create();
                info.Refresh();
            }

            using (var server = new LocalShellFolderServer(info))
            {
                var config = new ShellFolderConfiguration();
                if (register)
                {
                    config.NativeDllRegistration = RegistrationMode.User;
                }

#if DEBUG
                config.Logger = new Core.Utilities.ConsoleLogger();
#endif
                server.Start(config);

                var idl = ShellFolderServer.RootIdList;
                Console.WriteLine("Started listening on proxy id " + ShellFolderServer.ProxyId + ", folder id " + ShellFolderServer.FolderId + ". Press ESC key to stop serving folders.");
                Console.WriteLine("If you open Windows Explorer and have registered, you should now see the extension.");
                do
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                    {
                        break;
                    }

                    if (key.Key == ConsoleKey.C)
                    {
                        Console.Clear();
                        continue;
                    }
                }while (true);
                Console.WriteLine("Stopped");
            }
        }
Exemplo n.º 11
0
        static ConsoleKeyInfo Run()
        {
            ConsoleKeyInfo key;

            using (var server = new OverviewShellFolderServer())
            {
                var config = new ShellFolderConfiguration();
#if DEBUG
                config.Logger = new ShellBoost.Core.Utilities.ConsoleLogger {
                    AddCounter = true
                };
#endif
                server.Start(config);
                Console.WriteLine("Started listening on proxy id " + ShellFolderServer.ProxyId + ". Press ESC key to stop serving folders.");
                Console.WriteLine("If you open Windows Explorer, you should now see the extension under the ShellBoost.Overview folder.");
                try
                {
                    do
                    {
                        key = Console.ReadKey(true);
                        switch (key.Key)
                        {
                        case ConsoleKey.Escape:
                            break;

                        case ConsoleKey.C:
                            Console.Clear();
                            break;

                        default:
                            return(key);
                        }
                    }while (key.Key != ConsoleKey.Escape);
                }
                finally
                {
                    server.Stop();
                    Console.WriteLine("Stopped");
                }
            }
            return(key);
        }
Exemplo n.º 12
0
        static void Run()
        {
            Console.WriteLine("ShellBoost - Samples - SevenZip Folder - Copyright (C) 2018-" + DateTime.Now.Year + " Aelyo Softworks. All rights reserved.");
            Console.WriteLine(new DiagnosticsInformation(assembly: null).AssemblyDisplayName);
            Console.WriteLine();
            if (CommandLine.HelpRequested)
            {
                Help();
                return;
            }

            SetSevenZipLibraryPath();
            using (var server = new SevenZipShellFolderServer())
            {
                var config = new ShellFolderConfiguration();
                config.NativeDllRegistration = RegistrationMode.User;
#if DEBUG
                config.Logger = new ConsoleLogger {
                    AddThreadId = true
                };
#endif
                server.Start(config);

                RegisterAsVirtualFolder(".7z", ShellFolderServer.FolderId);

                Console.WriteLine("Started listening on proxy id " + ShellFolderServer.ProxyId + ". Press ESC key to stop serving 7z files.");
                do
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                    {
                        break;
                    }

                    if (key.Key == ConsoleKey.C)
                    {
                        Console.Clear();
                    }
                }while (true);
                Console.WriteLine("Stopped");
            }
        }
Exemplo n.º 13
0
#pragma warning disable CA1822 // Mark members as static
        public void Main(EventWaitHandle stop, string nativeDllPath)
#pragma warning restore CA1822 // Mark members as static
        {
            using (var server = new OverviewShellFolderServer())
            {
                var config = new ShellFolderConfiguration();
                config.NativeDllRegistration = RegistrationMode.User; // registration can also be done outside of ShellBoost (regsvr32, etc.)
                config.NativeDllPath         = nativeDllPath;

                server.Licensing += OnLicensing;
                Log("Starting listening");
                server.Start(config);
                Log("Started listening '" + ShellFolderServer.DisplayName + "' on proxy id " + ShellFolderServer.ProxyId + " Trace id " + ShellFolderServer.TraceId + ".");
                stop.WaitOne();

                // stop this instance, but keep global RPC listening
                server.Stop(ServerStopOptions.WaitForCallsToComplete | ServerStopOptions.DontStopListening);
                Log("Stopped listening");
                stop.Set();
            }
        }
Exemplo n.º 14
0
        static void Run(bool register)
        {
            // we may display some UI, let's do like regular winforms apps do
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (var server = new RegistryShellFolderServer())
            {
                var config = new ShellFolderConfiguration();
                if (register)
                {
                    config.NativeDllRegistration = RegistrationMode.User;
                }
#if DEBUG
                // add a logger that outputs to current console
                config.Logger = new ConsoleLogger {
                    AddThreadId = true
                };
#endif

                server.Start(config);
                Console.WriteLine("Started listening on proxy id " + ShellFolderServer.ProxyId + ". Press ESC key to stop serving folders.");
                Console.WriteLine("Folder class id " + ShellFolderServer.FolderId + ".");
                Console.WriteLine("If you open Windows Explorer and have registered, you should now see the extension.");
                do
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                    {
                        break;
                    }

                    if (key.Key == ConsoleKey.C)
                    {
                        Console.Clear();
                    }
                }while (true);
                Console.WriteLine("Stopped");
            }
        }
Exemplo n.º 15
0
        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;
            }
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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;
            }
        }