C# 不要使用c运行指定的Windows应用程序

C# 不要使用c运行指定的Windows应用程序,c#,.net-core,C#,.net Core,我想阻止访问我计算机上的某些应用程序。我在计算机上使用了gpedit.msc工具,其类别为:不运行特定的windows应用程序。 我现在正在寻找一种.netcore C算法,它可以自动阻止gpedit.msc中的应用程序 我使用以下代码: public static class GPAwareHelper { private const String REG_PATH = "Software\\Microsoft\\Windows\\CurrentVersion\\Poli

我想阻止访问我计算机上的某些应用程序。我在计算机上使用了gpedit.msc工具,其类别为:不运行特定的windows应用程序。 我现在正在寻找一种.netcore C算法,它可以自动阻止gpedit.msc中的应用程序

我使用以下代码:

public static class GPAwareHelper
{
    private const String REG_PATH =
       "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";

    public static Object GetGPOverride(
       String keyName, Object configValue)
    {
        Object keyValue = null;
        RegistryKey demoKey = null;

        //if (isHKLM)
        //    // open named key in HKEY_LOCAL_MACHINE section
        //    demoKey = Registry.LocalMachine.OpenSubKey(REG_PATH);
        //else
        //    // open named key in HKEY_CURRENT_USER section
            demoKey = Registry.CurrentUser.OpenSubKey(REG_PATH);

        if (demoKey != null)
        {
            // get the specified value from this key 
            keyValue = demoKey.GetValue(keyName);
            demoKey.Close();
            // check that a value was found and, if not, return `enter code here`
            // the value provided in method parameters
            if (keyValue != null)
            {

                return keyValue;
            }

            else
                return configValue;
        }
        else
        {
            // key not found, so return value provided 
            // in method parameters
            return configValue;
        }
    }

组策略是注册表项。只需使用.netcore编写这些注册表项

您可以通过在中添加密钥来阻止某些应用

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies
这是一个例子

要使用dotnet core编写注册表项,必须添加包Microsoft.Win32.registry


gpedit.msc只是策略的编辑工具。还有其他工具可用于此,例如您可以使用Powershell DSC。那么实际的问题是什么呢?策略也不仅仅是注册表中的键,域/操作系统本身将它们分发到多台机器并应用它们。修改注册表只会修改本地策略设置,这些设置可能随时被覆盖。它本身不会修改策略,这一点都不一样。操作系统本身可以将组策略应用于多台计算机。使用代码修改注册表一次只能在一台计算机上运行您需要的是:RegistryKey=registry.CurrentUser.CreateSubKeyHKEY\u CURRENT\u USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policys;key.SetValue2,AnyDesk.exe;键。关闭;
dotnet add package Microsoft.Win32.Registry