473,594 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check if Service Exists?

Hi all,

If I create a serviceControll er like:

srvController = New ServiceControll er("Fubar")

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

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

Thanks.

--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #1
4 15013
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() = ServiceControll er.GetServices( )
Dim i As Integer = 0

While i < scServices.Leng th
'MessageBox.Sho w(scServices(i) .DisplayName)
If scServices(i).D isplayName = "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 ServiceControll er("VNC Server")
End If
m_VNC.Refresh()

If m_VNC.Status <> ServiceControll erStatus.Stoppe d Then
tbVnc.ImageInde x = 7
tbVnc.Text = "VNC - ON"
End If

Catch exp As Exception
MsgBox(m_VNC.Se rviceName & " is in state:" &
m_VNC.Status.To String() & 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 serviceControll er like:

srvController = New ServiceControll er("Fubar")

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

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

Thanks.

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

Nov 21 '05 #2
"=?Utf-8?B?RGFycmVsbCB XZXNsZXk=?="
<Da***********@ discussions.mic rosoft.com> wrote in
news:5F******** *************** ***********@mic rosoft.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() = ServiceControll er.GetServices( )
Dim i As Integer = 0

While i < scServices.Leng th
'MessageBox.Sho w(scServices(i) .DisplayName)
If scServices(i).D isplayName = "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 ServiceControll er("NoSuchServi ce")

But it doesn't.

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

Thank you : )
--
Lucas Tam (RE********@rog ers.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() = ServiceControll er.GetServices( )
Dim i As Integer = 0

While i < scServices.Leng th
'MessageBox.Sho w(scServices(i) .DisplayName)
If scServices(i).D isplayName = "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 ServiceControll er("VNC Server")
End If
m_VNC.Refresh()

If m_VNC.Status <> ServiceControll erStatus.Stoppe d Then
tbVnc.ImageInde x = 7
tbVnc.Text = "VNC - ON"
End If

Catch exp As Exception
MsgBox(m_VNC.Se rviceName & " is in state:" &
m_VNC.Status.To String() & 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 serviceControll er like:

srvController = New ServiceControll er("Fubar")

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

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

Thanks.

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

Nov 21 '05 #4
"=?Utf-8?B?RGFycmVsbCB XZXNsZXk=?="
<Da***********@ discussions.mic rosoft.com> wrote in
news:5F******** *************** ***********@mic rosoft.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() = ServiceControll er.GetServices( )
Dim i As Integer = 0

While i < scServices.Leng th
'MessageBox.Sho w(scServices(i) .DisplayName)
If scServices(i).D isplayName = "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 ServiceControll er("NoSuchServi ce")

But it doesn't.

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

Thank you : )
--
Lucas Tam (RE********@rog ers.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
4504
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 "ENOENT", The file doesn't exist.
1
1681
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 display links to documents that actually exist. And alternatively generate a list of invalid links. Problem is that a link to an invalid document in some cases redirects
0
368
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 exception if I access the properties of the serviceController.
1
2816
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 Dim returnValue As Boolean = LogonUser(m_ntid, m_domain, m_pwd, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, tokenHandle)
2
17383
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 not resolve service name. Please advice!!
0
2825
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 calling the proc , if so i want to use the values in the temp table, else i will dummy them out in the proc.
4
2571
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 skip it. I thought I could check for the existence of an object by comparing to null. However, in the global.asax code below, the "if (Request == null)" line throws the error "Request is not available in this context".
0
1138
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 situations when I may extract up to 4 fields from the database but not all four may be populated. Is there any way with my ASP.net markup that I can check to see if the template field is not null before attempting to write out any markup.
2
9807
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 the document headers, not the data. request.Credentials = System.Net.CredentialCache.DefaultCredentials; // This may throw a WebException:
0
7936
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
7874
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
8366
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...
0
8227
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5738
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
5402
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
3853
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...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1203
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.