By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,199 Members | 1,440 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,199 IT Pros & Developers. It's quick & easy.

How to Monitor services using asp.net?

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.Stri ng")));

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

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

System.ServiceProcess.ServiceController[] arrSrvCtrl;

arrSrvCtrl = System.ServiceProcess.ServiceController.GetService s();

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" <An******@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
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.

Nov 18 '05 #2

P: n/a
Thank you, I will try this as soon as possible!
"Raghavendra T V" wrote:
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.Stri ng")));

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

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

System.ServiceProcess.ServiceController[] arrSrvCtrl;

arrSrvCtrl = System.ServiceProcess.ServiceController.GetService s();

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" <An******@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
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.


Nov 18 '05 #3

P: n/a
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/de...ersonation.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"AndersBj" <An******@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
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.

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.