I’m writing a CLI program that on an event, runs Process.Start() on a user-defined file. This respects %PATH%, but File.Open() does not.
Basically, when the program is launched, I run a variety of checks. One of the checks I want is that this file exists and can be opened by the current user, ala:
try
{
fs = File.Open(Run, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Run = args[++i];
}
catch(TheVariousExceptions){ .... }
finally
{
if(fs != null)
fs.Close();
}
The exceptions are also handled at the time of Process.Start(), but this may not be invoked until a while after, when the user might have configured the program and left it to run. So I’d like to first run the check like above. Problem is, it doesn’t take %PATH% into account.
Any ideas?
This is how I managed to do it.