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?
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.NativeErrorCodeto 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.