c# - 如何在 C# 中自动搜索和启动 exe?
问题描述
我正在 C# Visual Studio 2019 中编写一个应用程序,该应用程序将为用户启动 Microsoft Word。但是,我正在努力让应用程序搜索单词。我知道 word 安装在基于 64 位或 32 位 Windows、word 的确切版本等的不同位置。所以我通过尝试搜索 winword.exe 的程序文件来处理这个问题,然后在找到时启动它。如果找不到它,它会启动记事本。
string rootDirectory = System.IO.DriveInfo.GetDrives()[0].RootDirectory.FullName;
string [] files = System.IO.Directory.GetFiles(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
"WINWORD.EXE", System.IO.SearchOption.AllDirectories);
Process.Start(files);
}
catch (Exception e)
{
Console.WriteLine("I could not find word, so launching notepad.");
Process.Start("C:\\WINDOWS\\system32\\notepad.exe");
它使用字符串文件搜索单词,然后 process.start(stringname) 在找到时启动单词,但它返回此错误。任何想法将不胜感激,非常感谢。
解决方案
推荐阅读
- elixir - Elixir:主管、GenServer 和应用程序之间的区别
- dart - Flutter - 如何构建多个嵌套的 BLoC?
- c++ - 如何在数组中的所有最小值之后放置任何值 X?
- android - 如何在片段中拨打电话
- c++ - 铿锵警告:-Wambiguous-ellipsis
- multithreading - JavaFX:将线程保存在集合中是个好主意吗?以及如何做到这一点?
- php - Composer PSR-4 自动加载“找不到类”调试
- android - 错误:使用 adb reverse tcp:8081 tcp:8081 时有多个设备/模拟器
- html - Bootstrap 4 table-bordered 失去了它的风格
- javascript - 如何在 pathfinding3d.js 中的两个远程节点之间构建路径?