How to Monitor services using asp.net?

G

Guest

Is there a way to monitor a windows service using asp.net? I would like to
have a web page listing 5-6 services and their status (running, stopped etc).
Any tips on how to do this would be appreciated.
 
R

Raghavendra T V

Hi Anders,

Here is the piece of code that displays the services in the machine and also
there status.
Here in this code i am building a temp DataTable which inserting those
values into it.
so that it can be bind to Datagrid for display purpose.


using System.ServiceProcess;
DataTable dtSrvName = new DataTable();

dtSrvName.Columns.Add(new
DataColumn("ServiceName",Type.GetType("System.String")));

dtSrvName.Columns.Add(new
DataColumn("ServiceType",Type.GetType("System.String")));

dtSrvName.Columns.Add(new
DataColumn("Status",Type.GetType("System.String")));

System.ServiceProcess.ServiceController[] arrSrvCtrl;

arrSrvCtrl = System.ServiceProcess.ServiceController.GetServices();

foreach(System.ServiceProcess.ServiceController tmpSC in arrSrvCtrl)

{

DataRow drSrvName = dtSrvName.NewRow();


if(tmpSC.Status==ServiceControllerStatus.Running )

{

drSrvName[0] = tmpSC.DisplayName.ToString();

drSrvName[1] = tmpSC.ServiceType.ToString();

drSrvName[2] = tmpSC.Status.ToString();

}

else if(tmpSC.Status== ServiceControllerStatus.Paused )

{

drSrvName[0] = tmpSC.DisplayName.ToString();

drSrvName[1] = tmpSC.ServiceType.ToString();

drSrvName[2] = tmpSC.Status.ToString();

}

else

{

drSrvName[0] = tmpSC.DisplayName.ToString();

drSrvName[1] = tmpSC.ServiceType.ToString();

drSrvName[2] = tmpSC.Status.ToString();

}

dtSrvName.Rows.Add(drSrvName);

}

DataGrid1.Visible = true;

DataGrid1.DataSource = dtSrvName;

DataGrid1.DataBind();

lblStatus.Text = "";

Label1.Text = "";




Hope this helps you.

Thanks
Raghavendra
 
G

Guest

Thank you, I will try this as soon as possible!


Raghavendra T V said:
Hi Anders,

Here is the piece of code that displays the services in the machine and also
there status.
Here in this code i am building a temp DataTable which inserting those
values into it.
so that it can be bind to Datagrid for display purpose.


using System.ServiceProcess;
DataTable dtSrvName = new DataTable();

dtSrvName.Columns.Add(new
DataColumn("ServiceName",Type.GetType("System.String")));

dtSrvName.Columns.Add(new
DataColumn("ServiceType",Type.GetType("System.String")));

dtSrvName.Columns.Add(new
DataColumn("Status",Type.GetType("System.String")));

System.ServiceProcess.ServiceController[] arrSrvCtrl;

arrSrvCtrl = System.ServiceProcess.ServiceController.GetServices();

foreach(System.ServiceProcess.ServiceController tmpSC in arrSrvCtrl)

{

DataRow drSrvName = dtSrvName.NewRow();


if(tmpSC.Status==ServiceControllerStatus.Running )

{

drSrvName[0] = tmpSC.DisplayName.ToString();

drSrvName[1] = tmpSC.ServiceType.ToString();

drSrvName[2] = tmpSC.Status.ToString();

}

else if(tmpSC.Status== ServiceControllerStatus.Paused )

{

drSrvName[0] = tmpSC.DisplayName.ToString();

drSrvName[1] = tmpSC.ServiceType.ToString();

drSrvName[2] = tmpSC.Status.ToString();

}

else

{

drSrvName[0] = tmpSC.DisplayName.ToString();

drSrvName[1] = tmpSC.ServiceType.ToString();

drSrvName[2] = tmpSC.Status.ToString();

}

dtSrvName.Rows.Add(drSrvName);

}

DataGrid1.Visible = true;

DataGrid1.DataSource = dtSrvName;

DataGrid1.DataBind();

lblStatus.Text = "";

Label1.Text = "";




Hope this helps you.

Thanks
Raghavendra
AndersBj said:
Is there a way to monitor a windows service using asp.net? I would like to
have a web page listing 5-6 services and their status (running, stopped etc).
Any tips on how to do this would be appreciated.
 
S

Steve C. Orr [MVP, MCSD]

Simply drag the service from the Visual Studio.NET server explorer window
onto your web form.
You then have some objects you can interact with.
The only issue may be security since the standard ASPNET account doesn't
have permission to interact with windows services. Therefore you may need
to use impersonation to run under a different user account. For testing
purposes you can have it use your username and password.

Here's more info on impersonation:
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconaspnetimpersonation.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top