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

Check if Service Exists?

Hi all,

If I create a serviceController like:

srvController = New ServiceController("Fubar")

serviceController will be created regardless if the service exists or not.
It will only throw an exception if I access the properties of the
serviceController.

Is there a way to check that the service actually exists before creating
it?

Thanks.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #1
4 14988
DOn't know if this the correct way or not but it's what one of our programs
is doing to see if a Service is installed.

'
' Check to see if VNC is installed
'
Dim scServices() = ServiceController.GetServices()
Dim i As Integer = 0

While i < scServices.Length
'MessageBox.Show(scServices(i).DisplayName)
If scServices(i).DisplayName = "VNC Server" Then
m_bVNC = True
End If
i = i + 1
End While
If m_bVNC Then

'
' Check to see if VNC is already running, If so indecate
that VNC is running
'
Try

If m_VNC Is Nothing Then
m_VNC = New ServiceController("VNC Server")
End If
m_VNC.Refresh()

If m_VNC.Status <> ServiceControllerStatus.Stopped Then
tbVnc.ImageIndex = 7
tbVnc.Text = "VNC - ON"
End If

Catch exp As Exception
MsgBox(m_VNC.ServiceName & " is in state:" &
m_VNC.Status.ToString() & vbNewLine & _
"Could not start service")

Finally
m_VNC.Dispose()
m_VNC = Nothing
End Try

Else
tbVnc.Enabled = False

End If
"Lucas Tam" wrote:
Hi all,

If I create a serviceController like:

srvController = New ServiceController("Fubar")

serviceController will be created regardless if the service exists or not.
It will only throw an exception if I access the properties of the
serviceController.

Is there a way to check that the service actually exists before creating
it?

Thanks.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #2
"=?Utf-8?B?RGFycmVsbCBXZXNsZXk=?="
<Da***********@discussions.microsoft.com> wrote in
news:5F**********************************@microsof t.com:
DOn't know if this the correct way or not but it's what one of our
programs is doing to see if a Service is installed.

'
' Check to see if VNC is installed
'
Dim scServices() = ServiceController.GetServices()
Dim i As Integer = 0

While i < scServices.Length
'MessageBox.Show(scServices(i).DisplayName)
If scServices(i).DisplayName = "VNC Server" Then
m_bVNC = True
End If
i = i + 1
End While


Thank you - I was hoping to avoid looping through all my services. I was
sort of expecting that .NET would throw an error if it tried to create
an non-existing service.

i.e. New ServiceController("NoSuchService")

But it doesn't.

In anycase, the GetServices method way will work just fine for me.

Thank you : )
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #3
DOn't know if this the correct way or not but it's what one of our programs
is doing to see if a Service is installed.

'
' Check to see if VNC is installed
'
Dim scServices() = ServiceController.GetServices()
Dim i As Integer = 0

While i < scServices.Length
'MessageBox.Show(scServices(i).DisplayName)
If scServices(i).DisplayName = "VNC Server" Then
m_bVNC = True
End If
i = i + 1
End While
If m_bVNC Then

'
' Check to see if VNC is already running, If so indecate
that VNC is running
'
Try

If m_VNC Is Nothing Then
m_VNC = New ServiceController("VNC Server")
End If
m_VNC.Refresh()

If m_VNC.Status <> ServiceControllerStatus.Stopped Then
tbVnc.ImageIndex = 7
tbVnc.Text = "VNC - ON"
End If

Catch exp As Exception
MsgBox(m_VNC.ServiceName & " is in state:" &
m_VNC.Status.ToString() & vbNewLine & _
"Could not start service")

Finally
m_VNC.Dispose()
m_VNC = Nothing
End Try

Else
tbVnc.Enabled = False

End If
"Lucas Tam" wrote:
Hi all,

If I create a serviceController like:

srvController = New ServiceController("Fubar")

serviceController will be created regardless if the service exists or not.
It will only throw an exception if I access the properties of the
serviceController.

Is there a way to check that the service actually exists before creating
it?

Thanks.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #4
"=?Utf-8?B?RGFycmVsbCBXZXNsZXk=?="
<Da***********@discussions.microsoft.com> wrote in
news:5F**********************************@microsof t.com:
DOn't know if this the correct way or not but it's what one of our
programs is doing to see if a Service is installed.

'
' Check to see if VNC is installed
'
Dim scServices() = ServiceController.GetServices()
Dim i As Integer = 0

While i < scServices.Length
'MessageBox.Show(scServices(i).DisplayName)
If scServices(i).DisplayName = "VNC Server" Then
m_bVNC = True
End If
i = i + 1
End While


Thank you - I was hoping to avoid looping through all my services. I was
sort of expecting that .NET would throw an error if it tried to create
an non-existing service.

i.e. New ServiceController("NoSuchService")

But it doesn't.

In anycase, the GetServices method way will work just fine for me.

Thank you : )
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #5

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

Similar topics

10
by: Raymond | last post by:
Hi All: To find a file exists using the file name, I have tow routings on UNIX system. 1. access(2) 2. lstat(2) This tow function also can do. When the return value is "-1" and errno is...
1
by: Pete | last post by:
Hi, i'm building a datagrid that grabs a documents location out of a database and puts them in as a hyper link column. Ideally i'd love to be able to check the validity of the link and only...
0
by: Lucas Tam | last post by:
Hi all, If I create a serviceController like: srvController = New ServiceController("Fubar") serviceController will be created regardless if the service exists or not. It will only throw an...
1
by: James | last post by:
vb.net 2003 i wrote a windows service that does threading. My codes are a) the service thread will read a list of machine from a text file (machines.txt). b) it then logon using the below...
2
by: shikha tamta | last post by:
Hi!! I have oracle 8i&oracle 9i installed on my machine. I have set the tnsnames.ora file for Oracle 8i also. But whenevr i try to access the oracle 8i it throws the error: ORA 12154 TNS could...
0
by: Herb | last post by:
is there a way in an SQL stored proc to determine if a temp table exists before selecting from it....I have a java app. that is calling a stored proc. i want to check if Java created the table before...
4
by: Mark Berry | last post by:
Hi, I'm working on my "last resort" error block for a web application. If the error occurs after a Request has been made, I want to show the URL. If the Request object is not available, I'll...
0
by: philip.poole | last post by:
Hi everyone, I am settings up some .NET controls on my website and want to create template controls to completely separate the business layer and the presentation layer. However I have...
2
Manikgisl
by: Manikgisl | last post by:
HI. How to check File exists in Web Share C# try { WebRequest request = HttpWebRequest.Create("http://www.microsoft.com/NonExistantFile.aspx"); request.Method = "HEAD"; // Just get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.