Obtain System Service Information

Source: Internet
Author: User

You can choose "start"> "Control Panel"> "Management Tools"> "services" to view the services in the system, as shown in.

 

Introduce "system. serviceprocess. dll" in the project, and introduce the namespace in the class:

Using system. serviceprocess;

Example: displays all running information of the system, for example.

PageSource code:

View code

 1 <Asp: gridview id = "  Gv_state  " Runat = "  Server  " Gridlines = " None  " Borderwidth = "  0px  " Cellpadding = "  0  "  2 Cellspacing = "  1  " Align = "  Center  " Autogeneratecolumns = " False  " > 3 <Columns> 4 <Asp: templatefield headertext = "  ID name  " > 5 <Itemtemplate> 6 <% # (System. Data. datarowview) container. dataitem )[ "  Servicename  " ] %>7 </Itemtemplate> 8 <Itemstyle width = "  20%  " /> 9 </ASP: templatefield> 10 <Asp: templatefield headertext = "  Service Type  " > 11 <Itemtemplate> 12 <% # (System. Data. datarowview) container. dataitem )[ "  Servicetype  " ] %> 13 </Itemtemplate> 14 <Itemstyle width = "  20%  " /> 15 </ASP: templatefield> 16 <Asp: templatefield headertext = " Friendly name  " > 17 <Itemtemplate> 18 <% # (System. Data. datarowview) container. dataitem )[ "  Displayname  " ] %> 19 </Itemtemplate> 20 <Itemstyle width = "  20%  " />21 </ASP: templatefield> 22 <Asp: templatefield headertext = "  Service Status  " > 23 <Itemtemplate> 24 <% # (System. Data. datarowview) container. dataitem )[ "  Status  " ] %> 25 </Itemtemplate>26 <Itemstyle width = "  20%  " /> 27 </ASP: templatefield> 28 </Columns> 29 <Rowstyle cssclass = "  TR3  " Font-size = "  12px  " Height ="  28px  " /> 30 <Headerstyle cssclass = "  Itable_title  " /> 31 <Emptydatatemplate> 32 <Tr Class = "  Itable_title  " > 33 <TH width = "  25%  " > 34   ID name  35 </Th> 36 <TH width = "  25%  " > 37   Service Type  38 </Th>39 <TH width = "  25%  " > 40   Friendly name  41 </Th> 42 <TH width = "  25%  " > 43   Service Status  44 </Th> 45 </Tr> 46 <Tr Class = "  TR3  " > 47 <TD Class = "  Grid_no_result  " Colspan = "  4  " > 48 <Span> no query records currently </span> 49 </TD> 50 </Tr> 51 </Emptydatatemplate> 52 </ASP: gridview>

BackgroundCode:

View code

 1    Protected   Void Page_load ( Object Sender, eventargs E)  2   {  3               If (! Ispostback)  4   {  5 Servicecontroller [] Controller = Servicecontroller. getservices ();  6 Datatable dt = Createdatatable ();  7                   For (Int I = 0 ; I <controller. length; I ++ )  8   {  9                       If (Controller [I]. Status = Servicecontrollerstatus. Running)  10   {  11 Datarow DR = DT. newrow ();  12 Dr ["  Servicename  " ] = Controller [I]. servicename;  13 Dr [ "  Servicetype  " ] = Controller [I]. servicetype;  14 Dr [ "  Displayname  " ] = Controller [I]. displayname; 15 Dr [ "  Status  " ] = Controller [I]. status;  16   DT. Rows. Add (DR );  17   }  18   }  19                   This . Gv_state.datasource = DT;  20                  This  . Gv_state.databind ();  21   }  22   }  23   24           Public  Datatable createdatatable ()  25   {  26 Datatable dt = New  Datatable ();  27 DT. Columns. Add ( "  Servicename  " , Typeof ( String  ));  28 DT. Columns. Add ( "  Servicetype  " , Typeof ( String  ));  29 DT. Columns. Add ("  Displayname  " , Typeof ( String  ));  30 DT. Columns. Add ( "  Status  " , Typeof ( String  ));  31               Return  DT; 32 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.