473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Status of Windows Services

Hi,

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

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 :-)

Thanks

Scott

----------------------------------------------------

Imports System.ServiceProcess

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'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
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
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
InitializeComponent()
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(Form1))
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.SuspendLayout()
'
'comboBoxServer
'
Me.comboBoxServer.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList
Me.comboBoxServer.Items.AddRange(New Object() {"Server1",
"Server2"})
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
'
'Label1
'
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
'
'lblServiceStatus
'
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 =
System.Drawing.ContentAlignment.MiddleLeft
'
'Button1
'
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"
'
'lblService
'
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
'
'Label2
'
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
'
'comboBoxService
'
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
'
'btnStopService
'
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"
'
'btnStartService
'
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"
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1, Me.MenuItem3})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem2})
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "Exit"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem4, Me.MenuItem5})
Me.MenuItem3.Text = "About"
'
'MenuItem4
'
Me.MenuItem4.Index = 0
Me.MenuItem4.Text = "Help"
'
'MenuItem5
'
Me.MenuItem5.Index = 1
Me.MenuItem5.Text = "About"
'
'btnExit
'
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"
'
'Form1
'
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.comboBoxServer})
Me.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Icon = CType(resources.GetObject("$this.Icon"),
System.Drawing.Icon)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = "Control Panel"
Me.ResumeLayout(False)

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
Me.Close()
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
Me.Close()
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.",
"Help")
End Sub

Private Sub btnStopService_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnStopService.Click
Try
lblServiceStatus.Text = "Stopping service"
serviceControl.Stop()
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
Try
lblServiceStatus.Text = "Starting service"
serviceControl.Start()
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 3898

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

Similar topics

4
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...
1
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
2
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...
1
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,...
1
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...
1
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...
18
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?
11
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...
9
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.