GeoAvila (Geovanny G. Avila) Desarrollo.. de software.

14Aug/090

Listar Servicios de Windows con .Net

Bueno una función que nos puede ayudar en determinado momento es listar los servicios activos de Windows un ejemplo sencillo de como hacerlo es hacer usando System.Serviceprocess (NO olvides agregarlo como referencia al proyecto):

VB.NET:
  1. Imports System
  2. Imports System.ServiceProcess
  3.  
  4. Class Program
  5. Private Shared Sub Main()
  6. Dim services As ServiceController() = ServiceController.GetServices()
  7.  
  8. Console.WriteLine("Listado de los servicios corriendo : ")
  9. For Each service As ServiceController In services
  10. If service.Status = ServiceControllerStatus.Running Then 'cambiar por ServiceControllerStatus.Stopped para ver inactivos
  11. Console.WriteLine()
  12. Console.WriteLine(" Nombre de servicio: {0}", service.ServiceName)
  13. Console.WriteLine(" Nombre mostrado: {0}", service.DisplayName)
  14. End If
  15. Next
  16. End Sub
  17. End Class

y en c# sería así.

C#:
  1. using System;
  2. using System.ServiceProcess;
  3.  
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. ServiceController[] services = ServiceController.GetServices();
  9.  
  10. Console.WriteLine("Listado de los servicios corriendo : ");
  11. foreach (ServiceController service in services)
  12. {
  13. if (service.Status == ServiceControllerStatus.Running) //cambiar por ServiceControllerStatus.Stopped para ver inactivos
  14. {
  15. Console.WriteLine();
  16. Console.WriteLine(" Nombre de servicio: {0}",
  17. service.ServiceName);
  18. Console.WriteLine(" Nombre mostrado: {0}",
  19. service.DisplayName);
  20. }
  21. }
  22. }
  23. }

para saber los procesos que están inactivos usamos la siguiente propiedad.
ServiceControllerStatus.Stopped.

un buen truco espero les sirva.

No TweetBacks yet. (Be the first to Tweet this post)
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Sigueme en Twitter

Recent Posts

Amigos de Twitter

juliodemata
Gfita
ErikaPao
vaap2099
mitsumits
muniguate
elsum
josuepalacios
rudygiron
titiburgos
Ale928
andreitaQC
darkela
magjogui
AlcaldeArzu
jrhugo
axelopez
mysql
Microsoft
novell
google
lfer31
lexsoul
darkvander
SilvitaGG
anitagt
WendyGalvez
romerogt
arigalt
machpablo
wgavila
gnduran
anissette
eljorgeluis
xanderall
_Narima
Friends: 119 Followers: 204

Categories

Sitios amigos

Algunos Derechos Reservados

Blog bajo licencia Creative Commons Attribution-ShareAlike 3.0 License
Creative Commons License