473,753 Members | 7,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'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 lblServiceStatu s 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.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(Form 1))
Me.comboBoxServ er = New System.Windows. Forms.ComboBox( )
Me.Label1 = New System.Windows. Forms.Label()
Me.lblServiceSt atus = 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.comboBoxServ ice = New System.Windows. Forms.ComboBox( )
Me.btnStopServi ce = New System.Windows. Forms.Button()
Me.btnStartServ ice = 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.SuspendLayou t()
'
'comboBoxServer
'
Me.comboBoxServ er.DropDownStyl e =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st
Me.comboBoxServ er.Items.AddRan ge(New Object() {"Server1",
"Server2"})
Me.comboBoxServ er.Location = New System.Drawing. Point(104, 24)
Me.comboBoxServ er.Name = "comboBoxServer "
Me.comboBoxServ er.Size = New System.Drawing. Size(248, 21)
Me.comboBoxServ er.Sorted = True
Me.comboBoxServ er.TabIndex = 0
'
'Label1
'
Me.Label1.Locat ion = New System.Drawing. Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(88, 23)
Me.Label1.TabIn dex = 1
Me.Label1.Text = "Remote Server:"
Me.Label1.TextA lign = System.Drawing. ContentAlignmen t.MiddleLeft
'
'lblServiceStat us
'
Me.lblServiceSt atus.Location = New System.Drawing. Point(104, 88)
Me.lblServiceSt atus.Name = "lblServiceStat us"
Me.lblServiceSt atus.Size = New System.Drawing. Size(160, 24)
Me.lblServiceSt atus.TabIndex = 2
Me.lblServiceSt atus.TextAlign =
System.Drawing. ContentAlignmen t.MiddleLeft
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(232, 128)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing. Size(56, 23)
Me.Button1.TabI ndex = 3
Me.Button1.Text = "Status"
'
'lblService
'
Me.lblService.L ocation = New System.Drawing. Point(8, 88)
Me.lblService.N ame = "lblService "
Me.lblService.S ize = New System.Drawing. Size(80, 24)
Me.lblService.T abIndex = 4
Me.lblService.T ext = "Service Status:"
Me.lblService.T extAlign = System.Drawing. ContentAlignmen t.MiddleLeft
'
'Label2
'
Me.Label2.Locat ion = New System.Drawing. Point(8, 56)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing. Size(88, 23)
Me.Label2.TabIn dex = 7
Me.Label2.Text = "Remote Service:"
Me.Label2.TextA lign = System.Drawing. ContentAlignmen t.MiddleLeft
'
'comboBoxServic e
'
Me.comboBoxServ ice.Items.AddRa nge(New Object() {"Service 1",
"Service 2"})
Me.comboBoxServ ice.Location = New System.Drawing. Point(104, 56)
Me.comboBoxServ ice.Name = "comboBoxServic e"
Me.comboBoxServ ice.Size = New System.Drawing. Size(248, 21)
Me.comboBoxServ ice.TabIndex = 8
'
'btnStopService
'
Me.btnStopServi ce.Location = New System.Drawing. Point(104, 128)
Me.btnStopServi ce.Name = "btnStopService "
Me.btnStopServi ce.Size = New System.Drawing. Size(56, 23)
Me.btnStopServi ce.TabIndex = 9
Me.btnStopServi ce.Text = "Stop"
'
'btnStartServic e
'
Me.btnStartServ ice.Location = New System.Drawing. Point(168, 128)
Me.btnStartServ ice.Name = "btnStartServic e"
Me.btnStartServ ice.Size = New System.Drawing. Size(56, 23)
Me.btnStartServ ice.TabIndex = 10
Me.btnStartServ ice.Text = "Start"
'
'MainMenu1
'
Me.MainMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( )
{Me.MenuItem1, Me.MenuItem3})
'
'MenuItem1
'
Me.MenuItem1.In dex = 0
Me.MenuItem1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( )
{Me.MenuItem2})
Me.MenuItem1.Te xt = "File"
'
'MenuItem2
'
Me.MenuItem2.In dex = 0
Me.MenuItem2.Te xt = "Exit"
'
'MenuItem3
'
Me.MenuItem3.In dex = 1
Me.MenuItem3.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( )
{Me.MenuItem4, Me.MenuItem5})
Me.MenuItem3.Te xt = "About"
'
'MenuItem4
'
Me.MenuItem4.In dex = 0
Me.MenuItem4.Te xt = "Help"
'
'MenuItem5
'
Me.MenuItem5.In dex = 1
Me.MenuItem5.Te xt = "About"
'
'btnExit
'
Me.btnExit.Loca tion = New System.Drawing. Point(296, 128)
Me.btnExit.Name = "btnExit"
Me.btnExit.Size = New System.Drawing. Size(56, 23)
Me.btnExit.TabI ndex = 11
Me.btnExit.Text = "Exit"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(376, 163)
Me.Controls.Add Range(New System.Windows. Forms.Control() {Me.btnExit,
Me.btnStartServ ice, Me.btnStopServi ce, Me.comboBoxServ ice, Me.Label2,
Me.lblService, Me.Button1, Me.lblServiceSt atus, Me.Label1,
Me.comboBoxServ er})
Me.FormBorderSt yle =
System.Windows. Forms.FormBorde rStyle.FixedDia log
Me.Icon = CType(resources .GetObject("$th is.Icon"),
System.Drawing. Icon)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.StartPositio n =
System.Windows. Forms.FormStart Position.Center Screen
Me.Text = "Control Panel"
Me.ResumeLayout (False)

End Sub

#End Region

Dim serviceControl As New ServiceControll er()
Dim serviceStatus As String
Dim remoteServer As String
Dim remoteService As String

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

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

Private Sub btnExit_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnExit.Click
Me.Close()
End Sub

Private Sub MenuItem2_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MenuItem2.Click
Me.Close()
End Sub

Private Sub MenuItem4_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) Handles btnStopService. Click
Try
lblServiceStatu s.Text = "Stopping service"
serviceControl. Stop()
lblServiceStatu s.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.EventArg s) 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.EventArg s) Handles btnStartService .Click
Try
lblServiceStatu s.Text = "Starting service"
serviceControl. Start()
lblServiceStatu s.Text = "Service started"
Catch serviceControl As Exception
MessageBox.Show ("Unable to start service")
End Try
End Sub
End Class



Nov 20 '05 #1
0 3939

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

Similar topics

4
57124
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 file(s) defines the services (shown below)? What causes there to be more than one instance of a service (shown
1
1328
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
7165
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 windows form code behind I receive the following; {"The request failed with HTTP status 401: Unauthorized."} when trying to execute this.dataGridView1.DataSource = ws.ReturnStudentDS(); not sure if it is relevant but the web.config in the...
1
30017
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, see if the IP is reachable(if yes I will assume the pc is operational), update the database with the result and generate a web page displaying the results. I am using port 135 because I have an all windows network and this port should be open...
1
3454
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 going wrong. The program has been written to do the following tasks: - Select remote server - Select from two specific services
1
2362
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 reality the service is non-responsive. In light of this, I am using the ExecuteCommand method of the specified servicecontroller to "ping" teh service. In that method I pass it a command (an arbitrary number higher than 245). My understanding...
18
4146
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
8336
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 turn is called by another application). This all works fine in my development environment. Test environment: Windows Server 2003, ASP 6.0, .NET 2.0, Anonymous authentication is enabled. All components (web service, DLL, and calling application)...
9
4120
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 in another class from the main class. So it couldn't access the Status Line or textbox. So what we did was set them up as properties: string IStatusDisplay.Status
0
9072
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8896
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9451
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6869
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4771
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3395
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2284
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.