如何检查你是否有权限运行exe文件
C# .net 框架 4.0 有没有一种简单的方法来检查您是否有权运行文件?
在执行此操作之前:
//e.g. Press a button
....
string exePath = "D:\something\something.exe";
Process.Start(exePath);
我想检查用户是否有权运行该文件? 当我调用 Process.Start 函数时,窗口会弹出一个消息框,并提示我无权运行此应用程序,并且此应用程序是“D:\something\something.dat”而不是 .exe?
C# .net Framework 4.0
Is there a simple way to check if you have the rights to run a file?
Before i do this:
//e.g. Press a button
....
string exePath = "D:\something\something.exe";
Process.Start(exePath);
i would like to check if the user has the rights to run that file?
When i'm making the function call Process.Start, windows popsup with a messagebox and says that i'm not authorized to run this application and this application is "D:\something\something.dat" and NOT .exe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
EAFP:请求宽恕比获得许可更容易。
因此,您可以使用 try/catch 块包围代码:
并且可以使用
Win32Exception.NativeErrorCode
访问与此异常关联的错误代码的数字表示形式。有关错误代码的详细信息,请查看 Win32 系统错误代码。
EAFP: It is Easier to Ask Forgiveness than it is to get Permission.
So, you can surround your code with try/catch block:
and you can use
Win32Exception.NativeErrorCode
to access the numeric representation of the error code associated with this exception.For more information about the error codes, check out Win32 System Error Codes.
尝试使用
try catch
包围Proccess.Start
:即可完成这项工作。
Try surrounding
Proccess.Start
withtry catch
:that'll do the job.