private void RemoveProtectedServices()
        {
            PrivilegeUtils.GrantPrivilege(PrivilegeUtils.RESTORE_PRIVILEGE);
            PrivilegeUtils.GrantPrivilege(PrivilegeUtils.TAKE_OWNERSHIP_PRIVILEGE);

            using (RegistryKey allServicesKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services", true))
            {
                foreach (string serviceName in PROTECTED_TELEMETRY_SERVICES)
                {
                    try
                    {
                        RemoveProtectedService(serviceName, allServicesKey);
                        Console.WriteLine($"Service {serviceName} removed successfully.");
                    }
                    catch (KeyNotFoundException)
                    {
                        Console.WriteLine($"Service {serviceName} is not present or its key can't be retrieved.");
                    }
                    catch (Exception exc)
                    {
                        ConsoleUtils.WriteLine($"Error while trying to delete service {serviceName}: {exc.Message}", ConsoleColor.Red);
                    }
                }
            }

            PrivilegeUtils.RevokePrivilege(PrivilegeUtils.TAKE_OWNERSHIP_PRIVILEGE);
            PrivilegeUtils.RevokePrivilege(PrivilegeUtils.RESTORE_PRIVILEGE);
        }
Beispiel #2
0
        private void RemoveProtectedServices()
        {
            PrivilegeUtils.GrantTokenPrivilege(PrivilegeUtils.RESTORE_TOKEN_PRIVILEGE);
            PrivilegeUtils.GrantTokenPrivilege(PrivilegeUtils.TAKE_OWNERSHIP_TOKEN_PRIVILEGE);

            using (RegistryKey allServicesKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services", true))
            {
                foreach (string serviceName in protectedTelemetryServices)
                {
                    TryRemoveProtectedService(serviceName, allServicesKey);
                }
            }

            PrivilegeUtils.RevokeTokenPrivilege(PrivilegeUtils.TAKE_OWNERSHIP_TOKEN_PRIVILEGE);
            PrivilegeUtils.RevokeTokenPrivilege(PrivilegeUtils.RESTORE_TOKEN_PRIVILEGE);
        }
 private void GrantPermissionsOnAppRepository()
 {
     ConsoleUtils.WriteLine("\nGranting needed permissions...", ConsoleColor.Green);
     PrivilegeUtils.GrantFullControlOnDirectory(@"C:\ProgramData\Microsoft\Windows\AppRepository");
     PrivilegeUtils.GrantFullControlOnFile(STATE_REPOSITORY_DB_PATH);
 }