Hello guys, today I’m gonna show you a code about checking the program is installed or not on Windows system. This program controls all disk name (C:\ , D:\ etc.) and x64-x32 “Program Files” folders.
static bool ApplicationIsInstalled(string Name) { var ProgramList = new List {}; var PathList = new List { "Program Files", @"Program Files (x86)" }; //Check x64 and x32 files. foreach (var PathName in PathList) { DriveInfo[] allDrives = DriveInfo.GetDrives(); // Get drive names foreach (DriveInfo d in allDrives) { string[] subdirs = Directory.GetDirectories(d + PathName) .Select(Path.GetFileName) .ToArray(); // Get folder names foreach (string subDirectoryName in subdirs) ProgramList.Add(subDirectoryName.ToString()); // Add all folder names to list if (ProgramList.Contains(Name)) // Check a folder name { return true; } else { return false; } } } return false; } static void Main(string[] args) { if (ApplicationIsInstalled("Google") == true) { Console.WriteLine("[+] Success! Google is installed on your system."); } else { Console.WriteLine("[-] Failed! Google is not installed on your system."); } Console.ReadLine(); }
Also you can visit C# category for reading the other posts.
Referances:
https://stackoverflow.com/questions/19185655/how-to-get-drive-letter-and-name-volume-label
https://stackoverflow.com/questions/5229292/get-folder-name-from-full-file-path