472,986 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Status of Windows Services


I'm looking for some help on a small program that I'm trying to develop in

The program I'm trying to develop needs to be able to do the following:

- Select remote server
- Select from two specific services
- Check the status of the server
- Ability to stop/start selected service.

The problem that I've got is that the status only returns a numerical code
instead of "Running" or "Stopped" etc, and the status doesn't always appear
in my textbox. I also get a return value stating the service is stopped when
it is in fact started!!

Any help would be much appreciated as this is driving me mad :-)




Imports System.ServiceProcess

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

'This call is required by the Windows Form Designer.

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
End If
End If
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents comboBoxServer As System.Windows.Forms.ComboBox
Friend WithEvents comboBoxService As System.Windows.Forms.ComboBox
Friend WithEvents lblServiceStatus As System.Windows.Forms.Label
Friend WithEvents lblService As System.Windows.Forms.Label
Friend WithEvents btnStopService As System.Windows.Forms.Button
Friend WithEvents btnStartService As System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents btnExit As System.Windows.Forms.Button
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub
Dim resources As System.Resources.ResourceManager = New
Me.comboBoxServer = New System.Windows.Forms.ComboBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.lblServiceStatus = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.lblService = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.comboBoxService = New System.Windows.Forms.ComboBox()
Me.btnStopService = New System.Windows.Forms.Button()
Me.btnStartService = New System.Windows.Forms.Button()
Me.MainMenu1 = New System.Windows.Forms.MainMenu()
Me.MenuItem1 = New System.Windows.Forms.MenuItem()
Me.MenuItem2 = New System.Windows.Forms.MenuItem()
Me.MenuItem3 = New System.Windows.Forms.MenuItem()
Me.MenuItem4 = New System.Windows.Forms.MenuItem()
Me.MenuItem5 = New System.Windows.Forms.MenuItem()
Me.btnExit = New System.Windows.Forms.Button()
Me.comboBoxServer.DropDownStyle =
Me.comboBoxServer.Items.AddRange(New Object() {"Server1",
Me.comboBoxServer.Location = New System.Drawing.Point(104, 24)
Me.comboBoxServer.Name = "comboBoxServer"
Me.comboBoxServer.Size = New System.Drawing.Size(248, 21)
Me.comboBoxServer.Sorted = True
Me.comboBoxServer.TabIndex = 0
Me.Label1.Location = New System.Drawing.Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(88, 23)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Remote Server:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.lblServiceStatus.Location = New System.Drawing.Point(104, 88)
Me.lblServiceStatus.Name = "lblServiceStatus"
Me.lblServiceStatus.Size = New System.Drawing.Size(160, 24)
Me.lblServiceStatus.TabIndex = 2
Me.lblServiceStatus.TextAlign =
Me.Button1.Location = New System.Drawing.Point(232, 128)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 23)
Me.Button1.TabIndex = 3
Me.Button1.Text = "Status"
Me.lblService.Location = New System.Drawing.Point(8, 88)
Me.lblService.Name = "lblService"
Me.lblService.Size = New System.Drawing.Size(80, 24)
Me.lblService.TabIndex = 4
Me.lblService.Text = "Service Status:"
Me.lblService.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.Label2.Location = New System.Drawing.Point(8, 56)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(88, 23)
Me.Label2.TabIndex = 7
Me.Label2.Text = "Remote Service:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.comboBoxService.Items.AddRange(New Object() {"Service 1",
"Service 2"})
Me.comboBoxService.Location = New System.Drawing.Point(104, 56)
Me.comboBoxService.Name = "comboBoxService"
Me.comboBoxService.Size = New System.Drawing.Size(248, 21)
Me.comboBoxService.TabIndex = 8
Me.btnStopService.Location = New System.Drawing.Point(104, 128)
Me.btnStopService.Name = "btnStopService"
Me.btnStopService.Size = New System.Drawing.Size(56, 23)
Me.btnStopService.TabIndex = 9
Me.btnStopService.Text = "Stop"
Me.btnStartService.Location = New System.Drawing.Point(168, 128)
Me.btnStartService.Name = "btnStartService"
Me.btnStartService.Size = New System.Drawing.Size(56, 23)
Me.btnStartService.TabIndex = 10
Me.btnStartService.Text = "Start"
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1, Me.MenuItem3})
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
Me.MenuItem1.Text = "File"
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "Exit"
Me.MenuItem3.Index = 1
Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem4, Me.MenuItem5})
Me.MenuItem3.Text = "About"
Me.MenuItem4.Index = 0
Me.MenuItem4.Text = "Help"
Me.MenuItem5.Index = 1
Me.MenuItem5.Text = "About"
Me.btnExit.Location = New System.Drawing.Point(296, 128)
Me.btnExit.Name = "btnExit"
Me.btnExit.Size = New System.Drawing.Size(56, 23)
Me.btnExit.TabIndex = 11
Me.btnExit.Text = "Exit"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(376, 163)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnExit,
Me.btnStartService, Me.btnStopService, Me.comboBoxService, Me.Label2,
Me.lblService, Me.Button1, Me.lblServiceStatus, Me.Label1,
Me.FormBorderStyle =
Me.Icon = CType(resources.GetObject("$this.Icon"),
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = "Control Panel"

End Sub

#End Region

Dim serviceControl As New ServiceController()
Dim serviceStatus As String
Dim remoteServer As String
Dim remoteService As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
comboBoxServer.SelectedIndex = 1
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
remoteServer = comboBoxServer.SelectedItem
remoteService = comboBoxService.SelectedItem
serviceControl.MachineName = remoteServer
serviceControl.ServiceName = remoteService
serviceStatus = serviceControl.Status
lblServiceStatus.Text = serviceStatus
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem4.Click
MessageBox.Show("The Help function is unavailable in this version.",
End Sub

Private Sub btnStopService_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnStopService.Click
lblServiceStatus.Text = "Stopping service"
lblServiceStatus.Text = "Service stopped"
Catch serviceControl As Exception
MessageBox.Show("Unable to stop service")
End Try
End Sub

Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem5.Click
MessageBox.Show("2003 - Developed by xxxx", "About")
End Sub

Private Sub btnStartService_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnStartService.Click
lblServiceStatus.Text = "Starting service"
lblServiceStatus.Text = "Service started"
Catch serviceControl As Exception
MessageBox.Show("Unable to start service")
End Try
End Sub
End Class

Nov 20 '05 #1
0 3852

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Christian Eriksson | last post by:
Hi! I want to clarify, for myself, some basic facts about Oracle Client Server configuration. I start with the listener configuration on the server side. What block(s) in what configuration...
by: ehilario | last post by:
Thanks Mark, That 's better than internal server error. This is what came back, which is confusing because when its called locally it comes back fine. Am I missing something? -Ed
by: hazz | last post by:
I don't get it. I have a VS2005 solution with a web service project and a windows project. The web service when tested on its own works fine. But when I add it as a web reference and refer to it my...
by: gallaczmit | last post by:
Will this code give me a true view of a computer's status? All I am looking for is to see if the computer is reachable or not. My end goal is to get a list of IP addresses from a MS SQL Server,...
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
by: SQLScott | last post by:
In searching this site, i have seen plenty of posts and answers detailing how to check the status of a service. Many services, however, will "hang". Their status says that are running, but in...
by: mistral | last post by:
Is there some other (more advanced) effects for status bar, other than standard Scroller Bar, TypeWriter Scroller, Flashing Bar, Decrypter, Ticker, World Clock?
by: jjw92 | last post by:
I've been banging my head against the wall with this one for a couple days so I'm hoping someone has some ideas. I have a web service that I created that is called by a .NET class library (which in...
by: tshad | last post by:
I have a Windows App that is doing some work and then writing a "Now Processing..." line to the status line of the window as well as the Textbox on the form. But the problem is that the work is...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.