473,404 Members | 2,114 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,404 software developers and data experts.

Windows Services Status

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

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
1 3427
"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
wrong.
_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.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #2

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

Similar topics

3
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...
0
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).
4
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...
0
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 -...
4
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...
4
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...
3
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...
0
AmberJain
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)....
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.