I’m attempting to write a program that downloads Team Viewer and installs it and if its already installed, launch teamviewer from programfiles instead of re-downloading it.
I have it so it downloads and installs teamviewer into the correct folder but i cant figure out how to tell my program to search in either Program Files (x86) for 64bit or program files for 32 bit search the directory and sub directories for teamviewer.exe and launch the program. Here is the code i have so far.
Thanks.
I solved it using this code. It searches for Teamviewer in the correct program files folder and launches the program . This does not check if you have it installed or not, i have a check earlier in my program that detects it but it would be easy to add.
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
}
1 Answer