我正在尝试编写一个下载 Team Viewer 并安装它的程序,如果它已经安装,请从程序文件启动 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
}