进程类和.NET 安全性?
我在我的应用程序中使用 Process 类,就在 静态 Main 方法。 我正在使用 Process 类来了解是否有另一个 我的应用程序的实例当前正在运行。 如果我的申请是 已经运行了,我会退出。 我不是在寻找改变这一点的方法,这已经工作了很多年
,但最近这在我们用户的某些计算机上不起作用,我收到错误“公共语言运行时调试服务: 应用程序生成了无法处理的异常”。
我已经完全信任该程序集,并且用户是系统的管理员。
任何想法都会有所帮助,谢谢!
编辑:在引发错误之前,WMI 性能适配器服务已打开,并且错误发生后关闭,我是否缺少某种权限?
这是在 Framework 1.1 上
I am using the Process class in my application, right at the beginning of
the static Main method. I am using the Process class to know if another
instance of my application is currently running. If my application is
already running, I will exit. i am not looking for a way of change this, this has been working for years
But recently this is not working on some computers of our users, I get the error "Common Language Runtime Debugging Services :
Application has generated an exception that could not be handled".
I already fullstrust the assembly and the user is an administrator of the system.
any ideas will help Thanks!!
Edit: The WMI Performance Adapter Service is turned ON before the error is thrown and OFF after the error occurred, am i missing some kind of permission?.
this is on Framework 1.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
虽然我无法推测您的进程崩溃的原因,但更好的解决方案是使用命名互斥体:
While I can't speculate why your process crashes, a better solution would be to use a named mutex:
您可以添加一个顶级 try catch (或使用 UnhandledException 处理程序)来查看抛出的异常类型吗? 这会有很大的帮助。
Could you add a toplevel try catch (or use the UnhandledException handler) to see what kinf of Exception is thrown? This would be of great help.
我同意布莱恩的观点。 如果您不知道抛出了什么异常,则很难进行故障排除。 我会听 unhandledException 事件< /a> 并将问题记录为解决此问题的第一步。
I agree with Brann. It's hard to troubleshoot if you don't know what exception is being thrown. I'd listen to the unhandledexception event and log the issue as the first step in troubleshooting this.
我记得我正在处理的一些 .net 代码也遇到过类似的问题。 它位于 Citrix 环境中。
我相信用户必须是性能组的成员,才能运行 Process.GetProcessesByName()...这确实是不可取的!
我认为我们有两个解决方法 - 第一个是在代码的开头,即从 VB 脚本运行代码,该脚本测试代码是否已在运行。
第二个解决方法是设置窗口焦点的部分代码。 在这里,我们只是在 try / catch 块中运行 AppActivate() - 我猜你可能能够做到 - 如果 AppActivate 失败,那么你需要运行该应用程序。
希望这可以帮助!
I remember having a similar problem with some .net code that I was working on. It was in a citrix environment.
The user had to be a member of the performance group I believe, to be able to run Process.GetProcessesByName()... This isn't desirable really!
I think that we had two work arounds - the first was at the start of the code, and that was to run the code from a VB script, which tested to see whether the code was running already or not.
The second work around was in part of the code which set the window's focus. Here, we just run AppActivate() within a try / catch block - which I guess you might be able to do - if AppActivate fails, then you need to run the application.
Hope this helps!
.Net 提供 <用于此目的的 code>StartupNextInstance 应用程序事件。
嗯……没关系。 这看起来只能从 Visual Basic 中获得。 我会将答案留在这里,以防对其他人有用。
.Net provides the
StartupNextInstance
application event for this purpose.Hmm... never mind. This looks like it's only available from Visual Basic. I'll leave the answer here in case it's useful to someone else.