Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script to stop a service

Reply
 
Old 09-23-2009   #1 (permalink)
Cat


 
 

Script to stop a service

I am trying stop the service SQL Server VSS Writer using the following
as taken and modified from Microsoft website. The script appears to
run without errors but the service does not stop, any ideas on what I
need to add or modify to get it working.

' Start of Script
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root
\cimv2")

Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='NetDDE'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )

For Each objService in colServiceList
objService.StopService()
Next

Wscript.Sleep 20000

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='SQL Server VSS
Writer'")
For Each objService in colServiceList
errReturn = objService.StopService()
Next
'end of script

My System SpecsSystem Spec
Old 09-23-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Script to stop a service


"Cat" <cathossie@newsgroup> wrote in message
news:e4fa2257-91af-48cb-ab32-6ff955e12875@newsgroup
Quote:

>I am trying stop the service SQL Server VSS Writer using the following
> as taken and modified from Microsoft website. The script appears to
> run without errors but the service does not stop, any ideas on what I
> need to add or modify to get it working.
>
> ' Start of Script
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root
> \cimv2")
>
> Set colServiceList = objWMIService.ExecQuery("Associators of " _
> & "{Win32_Service.Name='NetDDE'} Where " _
> & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
>
> For Each objService in colServiceList
> objService.StopService()
> Next
>
> Wscript.Sleep 20000
>
> Set colServiceList = objWMIService.ExecQuery _
> ("Select * from Win32_Service where Name='SQL Server VSS
> Writer'")
> For Each objService in colServiceList
> errReturn = objService.StopService()
> Next
> 'end of script
Perhaps the services cannot be stopped. Can you stop them from a Command
Prompt like so:

net stop netdde
net stop "SQL Server VSS"


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Solved Help Stop running this script Msg Network & Sharing
how to stop confirmation in script PowerShell
how to stop service on vista General Discussion
How is it possible to execute start-service and stop-service through a Web-interface? PowerShell
which service can stop at VISTA? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46