Eziriz.Net.Reactor使用注意事项

本文介绍了解决.NET应用程序在更新注册表时遇到的权限问题的方法。通过添加应用程序清单文件来请求管理员权限,并使用代码检查当前用户的管理员角色,确保只有在拥有足够权限的情况下才尝试修改注册表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1) 保护参数配置

image

2) 注册表访问

 

using System.Security.Permissions;

[RegistryPermissionAttribute(SecurityAction.PermitOnly, All = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Jet 4.0")]
private static void UpdateOS32RegisterItem()
{
 	using (RegistryKey currentKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Jet\4.0\Engines\Jet 4.0", true))
	{
		currentKey.SetValue("MaxLocksPerFile", 0xF4240, RegistryValueKind.DWord);
		currentKey.Close();
	}
}

该种写法混淆后会出现如下的错误:

image

解决方法:

添加 应用程序清单文件,在其中加入

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC 清单选项
            如果希望更改 Windows 用户帐户控制级别,请用以下节点之一替换 
            requestedExecutionLevel 节点。

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            如果您希望利用文件和注册表虚拟化提供
            向后兼容性,请删除 requestedExecutionLevel 节点。
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

修改代码,如下:

private static void UpdateOS32RegisterItem()
 {
	System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
	System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal( identity );
	if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
	{
		using (RegistryKey currentKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Jet\4.0\Engines\Jet 4.0", true))
		{
			currentKey.SetValue("MaxLocksPerFile", 0xF4240, RegistryValueKind.DWord);
			currentKey.Close();
		}
	}
 }

 

转载于:https://www.cnblogs.com/janehlp/p/5379203.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值