Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if local service not exist then execute file

Status
Not open for further replies.

802dotjohn

Technical User
Dec 4, 2008
5
I have looked for a couple of days now and I am still not able to borrow enough code and piece it together to work. I am a beginner when it comes to trying to write this stuff. I have looked through this site as well as others including the purchase of a few books to help. I still can't get it.

What I am trying to do is run a vbscript on a local computer via a Group policy object. I would like the script to query the local computer to see if a service exists. Iff it does not exist then I want to execute a specified file.

I have found serveral ways to list services, but I don't know how to make an if not exists then X statement work after gathering this data.

Hope someone could give me a point in the right direction.

Thanks,
John
 
Post what you have that is listing the services and we can work from there.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
This is what I found on another board. It is reported to work. I have not been able to get it to work. Can i just tweak this one to launch an .exe if WMI_Service_Exists= False?



Set colServiceList = objServices.ExecQuery("Select * From
Win32_Service Where Name='" & _
strServiceName & "'")
'Error check
If (Err.Number = 0) And IsObject(colServiceList) Then
If colServiceList.Count > 0 Then
WriteOut " The " & strServiceName & " service exists."

'Set the function return value
WMI_Service_Exists = True
Else
'Set the function return value
WMI_Service_Exists = False

WriteOut " The " & strServiceName & " service does not exist."
End If
End If
 
In what way does it not work for you? Do you ever give strServiceName a value?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I get a line 9 char 58 Unterminated string constant error. Is this valid?


Option explicit
dim strServiceName
strServiceName = "Service Name"

Set colServiceList = objServices.ExecQuery("Select * From
Win32_Service Where Name='" & _
strServiceName & "'")
'Error check
If (Err.Number = 0) And IsObject(colServiceList) Then
If colServiceList.Count > 0 Then
WriteOut " The " & strServiceName & " service exists."

'Set the function return value
WMI_Service_Exists = True
Else
'Set the function return value
WMI_Service_Exists = False

WriteOut " The " & strServiceName & " service does not exist."
End If
End If
 
Get rid of the line break after From:

Set colServiceList = objServices.ExecQuery("Select * From
Win32_Service Where Name='" & _
strServiceName & "'")



[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Ok, I just tried that and now I am getting another error. I went back and referenced where I found this code and it was pulled out of a larger script. There was lots more going on prior to this part and other variables set prior to this. I don't think i can use this.

It was pulled from this large one:
Way too much going on in there for me figure how to get this small section to act the way I want.
 
I'm going to try to work this another way. Thanks anyway for the assistance EBGreen.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top