Edit: I didn’t mean to pinhole this question to a specific executable. I want this to work for any executable. If I was to type in the FileName into a run dialog, and the result is the “Windows cannot find …” dialog, then I dont want to Start that process. Updated below…
I would like to execute ‘an executable’ in my program, but if the user doesn’t have the executable installed, I want to run another process. How can I check BEFORE actually starting the visio process that visio is installed on the system? I do not want a popup “Windows cannot find “executable”…
Here’s my code. But this does give the “Windows cannot find “executable”..” error pop-up.
System.Diagnostics.Process myProc = new System.Diagnostics.Process();
myProc.StartInfo.FileName = "an executable.exe";
myProc.StartInfo.Arguments = "MyDoc.txt";
myProc.StartInfo.WorkingDirectory = "C:\MyFolder";
try
{
if( !myProc.Start() )
{
myProc.StartInfo.FileName = "another process.exe";
myProc.Start();
}
}
catch (Exception ex)
{
...
}
tldr; Something else causes the “Windows cannot find ..” dialog – what does the Exception handling code look like?
On a system without Visio the code
results in the helpful Exception being thrown
While this will result in Visio running if it is found, if Visio isn’t found, there is no inherent reason why a dialog message box is shown. That’s not normal behavior.
Now, if launching via
MyVisioDoc.vsddirectly (e.g. using the Open Verb) then yes, that is passed off to the windows system and may, if.vsdfiles are associated with a missing Visio application, result in such a dialog. However, this a different scenario than that presented in this post.