在程序文件中查找文件并启动该文件
本文关键字:文件 启动 程序 查找 | 更新日期: 2023-09-27 18:33:31
我正在尝试编写一个下载团队查看器并安装它的程序,如果已安装,请从程序文件启动 teamviewer 而不是重新下载它。
我有它,所以它将 teamviewer 下载并安装到正确的文件夹中,但我无法弄清楚如何告诉我的程序在程序文件 (x86) 中搜索 64 位或程序文件中搜索 32 位搜索目录和子目录 teamviewer.exe并启动程序。这是我到目前为止的代码。
谢谢。
我用这段代码解决了它。它在正确的程序文件文件夹中搜索Teamviewer并启动程序。这不会检查您是否安装了它,我在我的程序前面有一个检查可以检测到它,但它很容易添加。
private void teamviewerbtn_Click(object sender, EventArgs e)
{
//start button
if (Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").Contains("64"))
{
string path = @"c:'Program Files (x86)'Teamviewer'"; //specify starting folder location for searching
string searchPattern = "teamviewer.exe*"; //what do you want to search for?
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] files =
di.GetFiles(searchPattern, SearchOption.AllDirectories);
foreach (FileInfo file in files)
{
string tvE = (file.FullName.ToString()); //takes found file and references full file path
Process.Start(tvE);
}
}
else
{
string path = @"c:'Program Files'Teamviewer'"; //specify starting folder location for searching
string searchPattern = "teamviewer.exe*"; //what do you want to search for?
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] files =
di.GetFiles(searchPattern, SearchOption.AllDirectories);
foreach (FileInfo file in files)
{
string tvE = (file.FullName.ToString()); //takes found file and references full file path
Process.Start(tvE);
}
}
//end button
}
if (files.Length == 1)
{
Process.Start(files[0]);
}