473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to Monitor services using asp.net?

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
3 5727
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: vooose | last post by:
Suppose execution of a particular thread T1 hits Monitor.Enter(obj); //critical section and blocks at the first line. (ie someone else is in the critical section) Now suppose more threads...
3
by: maxim iulian | last post by:
I want to create o program in C# that's monitor IIS server. Thank's a lot ! Maxim Iulian *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get...
10
by: Mark | last post by:
I am working on a monitor system - web page that will show what processes are running on different computers. How would I get such information? All I need is a name of a process (title on a taskbar...
15
by: Jim Hubbard | last post by:
Is it possible to emulate a monitor (create a virtual monitor) using vb.net? Any code snippets or pointers to helpful articles would be very much appreciated.
1
by: Duncan S | last post by:
I am writing a service that uses the second monitor as a notice board the service runs okay if started when a user logs on. however the screen is blanked when the user logs out. is there any way a...
3
by: xerc | last post by:
So, this may not even be possible, but if so, I was hoping someone could point me in the right direction or give me the right terminology to use for searches of code example. Aside from monitoring...
1
by: dipak5801 | last post by:
i want to know how to monitor services using SNMP protocol. what is MIB and how can i get this information. anyone provide me training mateiral or step by step process using snapshot . thanks in...
1
by: vel | last post by:
Hi, How to monitor the local system services for each time interval using C#. I have to check whether the services are running properly or not. if any failur occurs i have to send a mail. Pls...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.