Created
January 12, 2020 15:10
-
-
Save Sheepings/099811c619511b352aa6a6b0aaae115e to your computer and use it in GitHub Desktop.
This code will return the list of installed program names and the install path if it exists.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Management; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace TestCSharpApp | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
MainMethod(); | |
} | |
public delegate void DelegateCallback(string s); | |
private void MainMethod() | |
{ | |
Task t = new Task(GetDependentObjects, TaskCreationOptions.LongRunning); | |
Thread tt = new Thread(GetDependentObjects, 0); | |
tt.Start(); | |
} | |
private void GetDependentObjects() | |
{ | |
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Product"); | |
foreach (ManagementObject queryObj in searcher.Get()) | |
{ | |
if (queryObj["Name"] != null && queryObj["InstallLocation"] != null) | |
{ | |
listBox1.Invoke(new DelegateCallback(UpdateUI), new string[] { string.Concat((string)queryObj["Name"], ", ", (string)queryObj["InstallDate"], ", ", (string)queryObj["InstallLocation"]) }); | |
} | |
} | |
} | |
private void UpdateUI(string item) | |
{ | |
listBox1.Items.Add(item); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment