简体   繁体   中英

System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified

I'm trying to open a document in either of two files using the below code:

try
{
    startInfo.FileName = "WINWORD.EXE";
}
catch(Win32Exception)
{
    startInfo.FileName = "TMViewer.exe";
}

I don't have MS Word on my laptop so I was hoping the catch would trigger it to open in a Word viewer program but I get that message:

System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified

I've upadating the registry to pick up the shortcut of running TMViewer.exe and it actually works on my other PC but if I try to run it on my laptop that doesn't have Word installed I keep getting this error.

The exception is thrown when you Start() the process, not when you set that option.

However, you don't need to do any of that.
Instead, just set FileName to the document you're trying to open, and Windows will automatically open it in the user's associated program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM