and there should be one service returned, and look at the StartMode and State or
Status properties.
--
Phil Wilson [MVP Windows Installer]
----
"Amador" <amador...@harpercollins.com> wrote in message
news:uOf$pFloDH...@tk2msftngp13.phx.gbl...
strComputer = InputBox ("Enter Computer Name","Enter Remote Computer
Name",".")
strService = InputBox ("Enter Service Name to Enumerate","Enumerate
Service",".")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ='" & strService & "'")
If colServices.Count > 0 Then
For Each objService in colServices
Wscript.Echo strService & " is currently " & objService.State & vbCrLF & _
"State is " & objService.StartMode
Next
Else
Wscript.Echo "SQL Server is not installed on this computer."
End If
So what I'm looking for is something that says if service = stopped and
startup mode = disabled, change startup mode to Automatic and start service,
and if service doesnt exist wscript.echo service does not exist. I have
several script and I know what I want but I'm having a hard time putting it
together.
Thanks
"Phil Wilson" <phil....@unisys.spamcom> wrote in message
news:ujW84Slo...@TK2MSFTNGP10.phx.gbl...
> Thanks Phil, I saw this script and I'm looking to modify it to start a
> service and change the mode if the service is stopped and is disabled. Can
> you help me out.So far this is all I have of the script.
>
> (snip some WMI code)
>
> So what I'm looking for is something that says if service = stopped and
> startup mode = disabled, change startup mode to Automatic and start service,
> and if service doesnt exist wscript.echo service does not exist. I have
> several script and I know what I want but I'm having a hard time putting it
> together.
Hi
I prefer to use the ADSI/WinNT provider and the IADsServiceOperations interface
to operate on services.
IADsServiceOperations
http://msdn.microsoft.com/library/en-us/netdir/adsi/iadsserviceoperations.asp
Here is a script that does what you want:
Const ADS_SERVICE_STOPPED = 1
Const ADS_SERVICE_RUNNING = 4
Const ADS_SERVICE_DISABLED = 4
Const ADS_SERVICE_AUTO_START = 2
Const ADS_SERVICE_DEMAND_START = 3
' service to operate on
sServiceName = "Fax"
' computer name or ip address, this example uses local computer
sCompName = CreateObject("WScript.Network").ComputerName
On Error Resume Next
Set oComputer = GetObject("WinNT://" & sCompName & ",computer")
If Err.Number <> 0 Then
WScript.Echo "Could not connect to computer " & sCompName
Else
Err.Clear
Set oService = oComputer.GetObject("Service", sServiceName)
If Err.Number <> 0 Then
WScript.Echo sCompName & " is likely missing service " & sServiceName
ElseIf oService.Status <> ADS_SERVICE_RUNNING Then
' service is not running,
' set it to startup mode Automatic if it is disabled
If oService.StartType = ADS_SERVICE_DISABLED Then
oService.StartType = ADS_SERVICE_AUTO_START
oService.SetInfo
WScript.Sleep 1000
End If
' start the service
oService.Start
End If
End If
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter