By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

get the status of a windows server service using

P: 5
THis is my code

Expand|Select|Wrap|Line Numbers
  1.     Public Class TS_Service
  3.         ' Is the service running?
  4.         ' Returns true if we need to start the service
  5.         Public Function CheckService(ByVal PC As String) As Boolean
  6.             Dim obj As ManagementObject
  7.             obj = New ManagementObject("\\" & PC & "\root\cimv2:Win32_Service.Name='SBAMSvc'")
  8.             '     If Not IsNothing(obj) Then
  9.             If obj("State").ToString = "Running" Then
  10.                 Return False
  11.                 'End If
  12.             End If
  13.             Return True
  14.         End Function

I am receiving an error,
Class 'myprojectname.managementobject' cannot be indexed because it has no default property
Jan 2 '13 #1
Share this Question
Share on Google+
7 Replies

Expert Mod 100+
P: 465
Try changing your Dim statement to look like this:

Expand|Select|Wrap|Line Numbers
  1. Dim obj As New ManagementObject("\\" & PC & "\root\cimv2:Win32_Service.Name='SBAMSvc'")
Jan 2 '13 #2

P: 5
Unfortunatly, this did not fix issue. same error
Jan 2 '13 #3

P: 5
I simplified my code but still same error.

Expand|Select|Wrap|Line Numbers
  1. Private Sub listservices3()
  2.         '  Dim obj As ManagementObject
  4.         Dim obj As New ManagementObject("\\server01\root\cimv2:Win32_Service.Name='tomcat6SPI'")
  5.       obj("State").ToString = "Running" Then
  6.         If obj("State").ToString = "Running" Then
  7.             Me.Label2.ForeColor = Color.AliceBlue
  8.         End If
  10.     End Sub
Jan 2 '13 #4

Expert Mod 10K+
P: 12,383
You need to declare a default property in the ManagementObject class. If you cannot, as I suspect it is a class where you don't have access to the source, then you must specify which property you are setting.
Jan 3 '13 #5

P: 5
I am unsure how to do this, but it seems like this is probably the issue. I am trying to get the Status of the service. the state which would be "Running", "Stopping" or blank(meaning Stopped)
Jan 3 '13 #6

Expert Mod 100+
P: 465
I guess you could contact the original writer of that code here and ask if they got the same error and if so how they resolved it.
Jan 3 '13 #7

Expert Mod 10K+
P: 12,383
Well, since you changed the way you are instantiating your object, the issue may be that you didn't escape your forward slashes.
Jan 3 '13 #8

Post your reply

Sign in to post your reply or Sign up for a free account.