A still unanswered NT Service question!!! [RESOLVED]
I searched the whole web. And searched all threads concerning NT Service in this forum and I found the exact same question that I'm asking myself and you guys.
Since nobody answered the other thread, I was hoping that maybe now the answer could come up. Tks in advance, here it goes:
How can I tell wheter a service is already installed or not?
Something like this:
VB Code:
' I made up this IsInstalled property of coarse just to show you what I need.
Sub cmdInstallService_Click()
If NTService.IsInstalled = False Then
NTService.Install
End If
End Sub
I need this because the user that is viewing my vb application wants to know wheter it is installed or not. If not, he clicks the button install and ok! I can't make the user go to Settings -> Control Panel and look for the service... I must be able to tell the user this information!
Tks :D
Re: A still unanswered NT Service question!!!
Welcome to the Forums.
You can use WMI reference in VB6 to list all services installed on a system.
VB Code:
Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_Service")
For each Service in ServiceSet
MsgBox Service.Description
Next
Re: A still unanswered NT Service question!!!
Quote:
Originally Posted by virtualblender
I searched the whole web. And searched all threads concerning NT Service in this forum and I found the exact same question that I'm asking myself and you guys.
Since nobody answered the other thread, I was hoping that maybe now the answer could come up. Tks in advance, here it goes:
How can I tell wheter a service is already installed or not?
Something like this:
VB Code:
' I made up this IsInstalled property of coarse just to show you what I need.
Sub cmdInstallService_Click()
If NTService.IsInstalled = False Then
NTService.Install
End If
End Sub
I need this because the user that is viewing my vb application wants to know wheter it is installed or not. If not, he clicks the button install and ok! I can't make the user go to Settings -> Control Panel and look for the service... I must be able to tell the user this information!
Tks :D
Well.. if you look into registry at HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services all the child nodes which which have the Type value set to >=10 (Hex) is a service....
I am not on VB machine... otherwise i would have enumerated the keys for u.. :)
Re: A still unanswered NT Service question!!!
RobDog888: I just tried this and it doesn't know what ServiceSet is. How do you declare that?
Re: A still unanswered NT Service question!!!
Quote:
Originally Posted by RobDog888
Welcome to the Forums.
You can use WMI reference in VB6 to list all services installed on a system.
VB Code:
Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_Service")
For each Service in ServiceSet
MsgBox Service.Description
Next
Wow.. never knew it's that easy... :)
VB Code:
Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_Service")
For Each Service In ServiceSet
Debug.Print Service.Name, Service.DisplayName, Service.Description
Next
virtualblender forget about my suggestion.. :)
Re: A still unanswered NT Service question!!!
Here you go.
VB Code:
Option Explicit
'Add a reference to MS WMI Scripting V1.2 Library
Private Sub Command1_Click()
Dim ServiceSet As Object
Dim Service As Object
Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_Service")
For Each Service In ServiceSet
MsgBox Service.Name & " - " & Service.Description
Next
End Sub
Re: A still unanswered NT Service question!!!
You can also execute a query against the database passing criteria for a particular service instead
of enumerating them.
VB Code:
Option Explicit
'Add a reference to MS WMI Scripting V1.2 Library
Private Sub Command1_Click()
Dim ServiceSet As Object
Dim Service As Object
'Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_Service")
Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_Service where name = 'Alerter'")
For Each Service In ServiceSet
MsgBox Service.Name & " - " & Service.Description
Next
End Sub
Quote:
Originally Posted by moinkhan
Wow.. never knew it's that easy... :)
Neither did I until I learned about the power of WMI. :)
Re: A still unanswered NT Service question!!!
Omg you guys are too fast! I thought of checking the forum only tomorrow but hey cool!
So tks for the welcome (I forgot to mention it's my first post ^^)
and of coarse... tks for the answer which worked perfectly. I'm using the query one that you mentioned
Tksss :D
Re: A still unanswered NT Service question!!! [RESOLVED]
Quote:
Originally Posted by virtualblender
Omg you guys are too fast! I thought of checking the forum only tomorrow but hey cool!
:D I think you will find that VB Forums is "The" best forum around. Usually you can get a reply within minutes, depending
on the time of day. I'm glad you didnt wait for tomorrow!
We are all glad to help and always happy to have new members. :thumb: