473,224 Members | 1,669 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,224 software developers and data experts.

Windows Services Status


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 going wrong.

The program has been written to do the following tasks:

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

I've listed the code below from mainFrm.vb:

Any help would be much appreciated.




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
1 3417
"Scott Davies" <sc******@ihatespam.btinternet.com> schrieb
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 going
_What_ is going wrong?
The program has been written to do the following tasks:

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

I've listed the code below from mainFrm.vb:

After reformatting the code and setting a reference to
System.ServiceProcess.dll, three errors remain. I guess you don't use option
strict (but you should). I don't see more errors.


Nov 20 '05 #2

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

Similar topics

by: Bart Nessux | last post by:
Can Python be used to stop windows services? I'm writing a script to automaically remove some troublesome Symantec software, but before running the main removal script, I need to kill some...
by: Stefan Hinz | last post by:
Degan, jumping in to try and solve some problems that look pretty obvious to me ... > #options for default service (mysqld2) > (mysqld2) It should be , not (mysqld2).
by: Bill Sonia | last post by:
I'm written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that once my send mail code is...
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. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... Following the samples online, we implemented a windows service in .Net. Like most services, there's a worker thread actually doing stuff in the background. The problem we've run into is...
by: Sylvie | last post by:
My Windows Application has two forms, one form contains a grid (lets say Stock Listing), and the other is a form of one stock, contains some edit boxes for one stock's fields.. Is it possible to...
by: AmberJain | last post by:
Windows Autorun FAQs: Overview NOTE- This complete article on "Windows Autorun FAQs" applies theoretically to all Windows NT-based OSes till Windows Vista (and probably Vista's successors too)....
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.