C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Retrieve a list of all windows Services


Posted Date: 15 May 2008    Resource Type: Articles    Category: .NET Framework
Author: Payal JainMember Level: Gold    
Rating: Points: 10



Introduction:


This Short Code will help you to retrieve the windows services running on a machine

Namespace to be included:


include the namespace System.ServiceProcess at the top of the code using :

using System.ServiceProcess;

functions used:


GetSevices function of ServiceController class returns a list services running other then Device Driver related services. for obtaining a list of device driver related services GetDevices function of the same class is used.



instances created

:
Create an instance of the class ServiceController .....As a list of services will be returned we will require to create an array instace of this class.2 instances will be created to contain two different list of services device driver and non-device driver services.

use the following code to generate lists of services and display them in 2 listboxes:




ServiceController[] NonDevice_services;

//GetServices method will retrieve non device driver services only
NonDevice_services = ServiceController.GetServices();

//if you want to retrieve services from a particular machine the give machine_name as parameter to GetServices method
//like :- NonDevice_services = ServiceController.GetServices("myMachine");

for (int i = 0; i < NonDevice_services.Length; i++)
{
lstNonDevice.Items.Add(NonDevice_services[i].ServiceName);
}

//retrieve device driver services
ServiceController[] device_Services;
device_Services = ServiceController.GetDevices();
for (int i = 0; i < device_Services.Length; i++)
{
lstDevice.Items.Add(device_Services[i].ServiceName);
}





Responses

Author: Mahesh Raj    07 Jun 2008Member Level: Gold   Points : 1
This is very good information,Continue posting such useful articles.


Author: John Fernandez    08 Jun 2008Member Level: Gold   Points : 1
Very well written Article.Thanks for sharing this information.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: NET Framework Journey from 1.0 to 3.5
Previous Resource: A few C# .Net questions and answers!
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use