Unable to check services remotely
Unable to check services remotely
Unable to check services remotely
Unable to check services remotely
Unable to check services remotely
Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely
Unable to check services remotely Unable to check services remotely
Unable to check services remotely
Go Back  Xtreme Visual Basic Talk > > > Unable to check services remotely


Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2011, 06:52 PM
--crafter-- --crafter-- is offline
Newcomer
 
Join Date: Jun 2011
Posts: 16
Post Unable to check services remotely


Im trying to check multiple services on different servers. The idea is that every time a client clicks on a checkbox for the specific server and press the "check service" button it will check the status on the service and if it's not running it will restart the service and so on for the rest of the servers.

This is what i have but it doesn't seem to be working for me.

Code:
Private Property Process As Process

 
        '================SERVER1 SERVER================'

        If SERVER1CheckBox.Checked = True Then
            Dim sc As New ServiceProcess.ServiceController("SERVER1")
            sc.ServiceName = "service"

            Try
                ' STOP THE SERVICE AND WAIT UNTILL ITS STATUS IS SET TO "STOPPED" '
                sc.Stop()
                sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

                ' DISPLAY THE CURRENT SERVICE STATUS '
                MessageBox.Show("The service is currently set to stopped")

            Catch ex As Exception
                If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    MessageBox.Show("Unable to stop the service....try again.")
                End If
            End Try
        End If

        '================SERVER2 SERVER================'


        If SERVER2CheckBox.Checked = True Then
            Dim sc As New ServiceProcess.ServiceController("SERVER2")
            sc.ServiceName = "Service2"

            Try
                ' Stop the service, and wait until its status is "Stopped".
                sc.Stop()
                sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

                ' Display the current service status.
                MessageBox.Show("The service status is now set to stopped")

            Catch ex As Exception
                If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    MessageBox.Show("Unable to stop service....try again")
                End If
            End Try
        End If

        If SERVER2CheckBox.Checked = True Then
            Dim sc As New ServiceProcess.ServiceController("SERVER2")
            sc.ServiceName = "service"

            Try
                ' Stop the service, and wait until its status is "Stopped".
                sc.Stop()
                sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

                ' Display the current service status.
                MessageBox.Show("The service status is now set to stopped")

            Catch ex As Exception
                If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    MessageBox.Show("Unable to stop service....try again")
                End If
            End Try
        End If

        If SERVER2CheckBox.Checked = True Then
            Dim sc As New ServiceProcess.ServiceController("SERVER2")
            sc.ServiceName = "service"

            Try
                ' Stop the service, and wait until its status is "Stopped".
                sc.Stop()
                sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

                ' Display the current service status.
                MessageBox.Show("The service status is now set to stopped")

            Catch ex As Exception
                If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    MessageBox.Show("Unable to service....try again")
                End If
            End Try
        End If


        '================SERVER3 SERVER================'


        If SERVER3CheckBox.Checked = True Then
            Dim sc As New ServiceProcess.ServiceController("SERVER3")
            sc.ServiceName = "service"

            Try
                ' Stop the service, and wait until its status is "Stopped".
                sc.Stop()
                sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

                ' Display the current service status.
                MessageBox.Show("The service status is now set to stopped")

            Catch ex As Exception
                If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    MessageBox.Show("Unable to stop  service....try again")
                End If
            End Try
        End If

        If SERVER3CheckBox.Checked = True Then
            Dim sc As New ServiceProcess.ServiceController("SERVER3")
            sc.ServiceName = "service"

            Try
                ' Stop the service, and wait until its status is "Stopped".
                sc.Stop()
                sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

                ' Display the current service status.
                MessageBox.Show("The service status is now set to stopped")

            Catch ex As Exception
                If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    MessageBox.Show("Unable to stop service....try again")
                End If
            End Try
        End If

        '================SERVER4 SERVER================'

        If SERVER4CheckBox.Checked = True Then
            Dim sc As New ServiceProcess.ServiceController("SERVER4")
            sc.ServiceName = "service"

            Try
                ' Stop the service, and wait until its status is "Stopped".
                sc.Stop()
                sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

                ' Display the current service status.
                MessageBox.Show("The service status is now set to stopped")

            Catch ex As Exception
                If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    MessageBox.Show("Unable to stop service....try again")
                End If
            End Try
        End If

    End Sub
Any help is appreciated.
Reply With Quote
  #2  
Old 07-10-2011, 10:50 PM
AtmaWeapon's Avatar
AtmaWeaponUnable to check services remotely AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

The ServiceController constructor overload that takes one string uses that string as the name of the service, not the name of the computer. When you create your service controller, it is managing the services on your machine. If you want to control services on a remote machine, use the overload that takes a server name. Alternatively, it looks like you can set the MachineName property.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 07-11-2011, 03:11 AM
--crafter-- --crafter-- is offline
Newcomer
 
Join Date: Jun 2011
Posts: 16
Default

Just a side note... this website has helped a whole lot more than the actual Visual Basic Developer Center at Microsoft...every time i ask something i always get a smart$$$ response.

Thank you so much.. im learning as i go i just need to be pointed in the right direction.

Thanks again...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Unable to check services remotely
Unable to check services remotely
Unable to check services remotely Unable to check services remotely
Unable to check services remotely
Unable to check services remotely
Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely Unable to check services remotely
Unable to check services remotely
Unable to check services remotely
 
Unable to check services remotely
Unable to check services remotely
 
-->