{"id":118,"date":"2006-12-14T12:43:49","date_gmt":"2006-12-14T17:43:49","guid":{"rendered":"\/cgi\/wp\/?p=118"},"modified":"2006-12-14T18:51:39","modified_gmt":"2006-12-14T23:51:39","slug":"aspnet-monitor-windows-services","status":"publish","type":"post","link":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/?p=118","title":{"rendered":"ASP.NET Monitor Windows Services"},"content":{"rendered":"<p>Today I had to troubleshoot a mail problem on a web server. I needed to determine if the SMTP Service was running. I used to have an ASP script to list Windows Services and their status but I needed something written in ASP.NET. As usual, I had problems finding any sample code on the Internet and there was a technical issue  that frustrated me. The technical problem is that you need to manually add a reference to System.ServiceProcess in Visual Studio.NET 2003. You cannot use an Imports statement to reference that Namespace.<\/p>\n<pre>\r\n    <font color= \"blue\">Private<\/font> <font color= \"blue\">Sub<\/font> Page_Load(ByVal sender <font color= \"blue\">As<\/font> System.Object, ByVal e <font color= \"blue\">As<\/font> System.EventArgs) Handles <font color= \"blue\">MyBase<\/font>.Load\r\n        <font color= \"green\">'Put user code to initialize the page here<\/font>\r\n        <font color= \"green\">' Define a DataSet with a single DataTable.<\/font>\r\n        ds.Clear()\r\n        ds.Tables.Add(&quot;Services&quot;)\r\n\r\n        <font color= \"green\">' Define two columns for this table.<\/font>\r\n        ds.Tables(&quot;Services&quot;).Columns.Add(&quot;service_name&quot;)\r\n        ds.Tables(&quot;Services&quot;).Columns.Add(&quot;service_status&quot;)\r\n\r\n        <font color= \"blue\">Try<\/font>\r\n            <font color= \"blue\">Dim<\/font> services() <font color= \"blue\">As<\/font> System.ServiceProcess.ServiceController\r\n            services = System.ServiceProcess.ServiceController.GetServices()\r\n            <font color= \"blue\">Dim<\/font> iCounter <font color= \"blue\">As<\/font> <font color= \"blue\">Integer<\/font>\r\n\r\n            <font color= \"blue\">For<\/font> iCounter = 0 To services.Length - 1\r\n                rs = ds.Tables(&quot;Services&quot;).NewRow()\r\n                rs(&quot;service_name&quot;) = services(iCounter).DisplayName\r\n                rs(&quot;service_status&quot;) = services(iCounter).Status\r\n                ds.Tables(&quot;Services&quot;).Rows.Add(rs)\r\n            <font color= \"blue\">Next<\/font>\r\n\r\n            rptServices.DataSource = ds\r\n            rptServices.DataBind()\r\n        <font color= \"blue\">Catch<\/font> ex <font color= \"blue\">As<\/font> Exception\r\n            lblError.Text = ex.Message &amp; &quot;&lt;br&gt;&quot; &amp; ex.StackTrace\r\n        <font color= \"blue\">End Try<\/font>\r\n    <font color= \"blue\">End Sub<\/font>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today I had to troubleshoot a mail problem on a web server. I needed to determine if the SMTP Service was running. I used to have an ASP script to list Windows Services and their status but I needed something &hellip; <a href=\"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/?p=118\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/posts\/118"}],"collection":[{"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=118"}],"version-history":[{"count":0,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/posts\/118\/revisions"}],"wp:attachment":[{"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}