从 C# 控制台应用程序调用时出现RegistryPermission 错误

发布于 2024-07-19 18:45:39 字数 1182 浏览 8 评论 0原文

只是在走上错误的道路之前寻找一些指示。 我编写了小型 C# 控制台应用程序,可以在 HKEY_LOCAL_MACHINE 和 HKEY_CURRENT_USER 下从我们的用户注册表中打开、读取、写入和删除

当然,我让它在我的 PC 和所有测试 PC 上运行,但我们的一个客户端在运行时出现错误他们尝试运行 .exe

System.Security.SecurityException:请求“System.Security.Permissions.RegistryPermission,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”类型的权限失败。< /p>

at System.Security.CodeAccessSecurityEngine.Check(对象需求, StackCrawlMark&stackMark, Boolean isPermSet) 在 System.Security.CodeAccessPermission.Demand() 在 Microsoft.Win32.RegistryKey.CheckSubKeyReadPermission(String subkeyName) 在 Microsoft.Win32.RegistryKey.CheckOpenSubKeyPermission(String subkeyName, Boolean > subKeyWritable) 在 Microsoft.Win32.RegistryKey.OpenSubKey(字符串名称,布尔可写) 在 EstateMasterClearReg.Program.Main(String[] args)

失败的操作是:

需求。 第一个失败的权限类型是: 系统.安全.权限.RegistryPermission 失败的装配区域是: 内联网

由于我无法在客户端计算机上对此进行测试(他们说他们有本地运行的 .exe 并以管理员身份登录),所以我可以做些什么来尝试确保该应用程序将在 Intranet 上 任何机器?

我是否需要使用强名称密钥和AllowPartiallyTrustedCallers,还是应该使用System.Security.Permissions.RegistryPermission?

感谢您的帮助。

Just looking for some pointer before I head down the wrong path. I have written small C# console app that opens, reads, writes and deletes from our users registry under both HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER

Of course, I got it to work on my PC and all the test PC but one of our clients is getting an error when they try to run the .exe

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at Microsoft.Win32.RegistryKey.CheckSubKeyReadPermission(String subkeyName)
at Microsoft.Win32.RegistryKey.CheckOpenSubKeyPermission(String subkeyName, Boolean > subKeyWritable)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at EstateMasterClearReg.Program.Main(String[] args)

The action that failed was:

Demand.
The type of the first permission that failed was:
System.Security.Permissions.RegistryPermission
The Zone of the assembly that failed was:
Intranet

As I won't be able to test this on the client machines (and they said that they have the .exe running locally and are logged in as Admin) is there anything I can do to try and ensure that the app will run on any machine?

Do I need to use a strong name key and AllowPartiallyTrustedCallers or should I use System.Security.Permissions.RegistryPermission?

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁人与我共长歌 2024-07-26 18:45:39

看起来他们可能正在通过网络运行您的可执行文件。 让他们尝试将其复制到本地硬盘并再次运行。 从网络共享运行与从本地文件系统运行之间,分配给可执行文件的权限有所不同。

或者,他们也可能修改了默认安全设置,因此即使它在本地运行,它也被视为 Intranet 区域的一部分。 也检查一下。

这里的提示也可能有帮助:

http://blogs. msdn.com/shawnfa/archive/2003/06/20/57023.aspx

请注意,如果您为程序集指定了强名称,则仍然需要修改本地安全策略,以便为程序集提供适当的权限。 强名称本身不会授予所需的额外权限。

Looks like they may be running your executable over the network. Have them try copying it to a local hard drive and run again. The permissions assigned to the executable differ between running it from a network share vs. running from the local file system.

Alternatively, it could be possible that they have modified the default security settings, so that even if it is running locally, it is considered part of the Intranet zone. Check those, too.

The tips here may also be helpful:

http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx

Note that if you give your assembly a strong name, you'll still need local security policy to be modified to give your assembly the appropriate permissions. The strong name by itself won't grant the additional permission required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文