.Net控制台应用程序不断崩溃 [英] .Net Console App keeps crashing

查看:296
本文介绍了.Net控制台应用程序不断崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在清单文件中添加了元素

I added the Manifest file with the element

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

我构建了该项目,当非管理员运行该项目时,它一直崩溃.

I built the project and it keeps crashing when a non-administrator runs it.

未处理的异常:System.Security.SecurityException:请求 类型的许可 'System.Security.Permissions.RegistryPermission,mscorlib,版本= 2. 0.0.0,文化=中性,PublicKeyToken = b77a5c561934e089'失败.在System.Security.CodeAccessSecurityEngine.Check(对象需求, StackCrawlMa rk& amp; stackMark,布尔值isPermSet) System.Security.CodeAccessPermission.Demand()在 Microsoft.Win32.RegistryKey.CheckSubKeyReadPermission(String subkeyName)位于 Microsoft.Win32.RegistryKey.CheckOpenSubKeyPermission(String subkeyName,Boolean subKeyWritable),位于 Microsoft.Win32.RegistryKey.OpenSubKey(字符串名称,可写布尔值) 在 LotusTrustedSites.RegistryKeyExtensionMethods.GetOrCreateSubKey(RegistryKe y RegistryKey,字符串parentKeyLocation,字符串键,可写布尔值) 在LotusTrustedSites.ReportDownloader.Main(String [] args)的操作 失败的是:需求失败的第一个权限的类型 原为:System.Security.Permissions.RegistryPermission

Unhandled Exception: System.Security.SecurityException: Request for the permissi on of type 'System.Security.Permissions.RegistryPermission, mscorlib, Version=2. 0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMa rk& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at Microsoft.Win32.RegistryKey.CheckSubKeyReadPermission(String subkeyName) at Microsoft.Win32.RegistryKey.CheckOpenSubKeyPermission(String subkeyName, B oolean subKeyWritable) at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) at LotusTrustedSites.RegistryKeyExtensionMethods.GetOrCreateSubKey(RegistryKe y registryKey, String parentKeyLocation, String key, Boolean writable) at LotusTrustedSites.ReportDownloader.Main(String[] args) The action that failed was: Demand The type of the first permission that failed was: System.Security.Permissions.RegistryPermission

失败的程序集或AppDomain是:MyApp,版本= 1.0.0.0, Culture = neutral,PublicKeyToken = null导致 失败是:Microsoft.Win32.RegistryKey GetOrCreateSubKey(Microsoft.Win32.RegistryKey,Syste m.String, System.String,布尔)

The assembly or AppDomain that failed was: MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null The method that caused the failure was: Microsoft.Win32.RegistryKey GetOrCreateSubKey(Microsoft.Win32.RegistryKey, Syste m.String, System.String, Boolean)

推荐答案

当然,它会失败.您告诉它要求管理员访问权限,而非管理员帐户则无法提供该权限.您是否希望它以非管理员用户的管理员权限运行?如果可能的话,那将是Windows中的主要安全漏洞.

Of course it fails. You told it to require administrator access, and non-administrator accounts don't have the ability to provide that. Did you expect it to run with administrator privileges for non-admin users? That would be a major security flaw in Windows if it were possible.

如果您需要让非管理员可以访问的应用程序以管理员身份运行,那么我唯一知道的方法是将应用程序安装为计划任务,并将该任务设置为使用管理员帐户运行.非管理员仍然应该能够查看和运行此任务,它将使用提供的管理员凭据.

If you need an app to run as an administrator that is accessible to non-admins, the only way I know to do it is to install the app as a scheduled task, and set the task to run using an admin account. Non-admins should still be able to see and run this task, and it will use the supplied admin credentials.

这篇关于.Net控制台应用程序不断崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆