Load list of services

Bubbly
Posted by Bubbly under C# category on | Views : 1969
private ServiceController msvc;
private ListViewItem ViewItem;
private Hashtable mcolSvcs = new Hashtable();
private bool fUpdatingUI ;

private void frmMain_Load(object sender, System.EventArgs e)
{
EnumServices();
}

private void EnumServices()
{
// Get the list of available services and load the list view control with the information
try
{
fUpdatingUI = true;
this.lvServices.Items.Clear();
if (!(mcolSvcs == null))
{
mcolSvcs = new Hashtable();
}

ServiceController[] svcs = ServiceController.GetServices();

foreach(ServiceController svc in svcs)
{
ViewItem = this.lvServices.Items.Add(svc.DisplayName);
ViewItem.SubItems.Add(svc.Status.ToString());
ViewItem.SubItems.Add(svc.ServiceType.ToString());
mcolSvcs.Add(svc.DisplayName,svc);
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
fUpdatingUI = false;
}
}

Comments or Responses

Login to post response