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 - Starting & stopping services

Reply
 
Old 01-13-2009   #1 (permalink)
Joe Blow


 
 

Starting & stopping services

I found this code snippet that I am using, but would like some explanation
on a couple of points.

1. "StdOut", I only see where it is being set, but not used anywhere. What
is it, why would it be there (i.e. did I miss some other part of the snippet
possibly that uses it but I don't need it?).
2. When stopping the dependent services, it has errReturn =
objService.StopService(), but when the main service stops, it does
not...why?
3. What are the error return values equal to? I have found 4 so far in my
testing
a. 0 = Success (most likely)
b. 1 =
c. 5 =
d. 10 =

Thanks!

<code>
strComputer = "."
Set StdOut = WScript.StdOut
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
StopService "'EnterpriseVaultAdminService'"
Sub StopService(strService)
Set colServiceList = objWMIService.ExecQuery("Associators of
{Win32_Service.Name=" & strService & "} _
Where AssocClass=Win32_DependentService Role=Antecedent")
For Each objService in colServiceList
objService.StopService()
Next
WScript.Sleep 10000
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service
where Name=" & strService)
For Each objService in colServiceList
errReturn = objService.StopService()
Next
End Sub
</code>



My System SpecsSystem Spec
Old 01-13-2009   #2 (permalink)
Joe Blow


 
 

Re: Starting & stopping services

Sorry, bad typing, on Q3b should be errReturn 3

Thanks


"Joe Blow" <joe@xxxxxx> wrote in message
news:u6Mf7MZdJHA.1328@xxxxxx
Quote:

>I found this code snippet that I am using, but would like some explanation
>on a couple of points.
>
> 1. "StdOut", I only see where it is being set, but not used anywhere.
> What is it, why would it be there (i.e. did I miss some other part of the
> snippet possibly that uses it but I don't need it?).
> 2. When stopping the dependent services, it has errReturn =
> objService.StopService(), but when the main service stops, it does
> not...why?
> 3. What are the error return values equal to? I have found 4 so far in
> my testing
> a. 0 = Success (most likely)
> b. 1 =
> c. 5 =
> d. 10 =
>
> Thanks!
>
> <code>
> strComputer = "."
> Set StdOut = WScript.StdOut
> Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> StopService "'EnterpriseVaultAdminService'"
> Sub StopService(strService)
> Set colServiceList = objWMIService.ExecQuery("Associators of
> {Win32_Service.Name=" & strService & "} _
> Where AssocClass=Win32_DependentService Role=Antecedent")
> For Each objService in colServiceList
> objService.StopService()
> Next
> WScript.Sleep 10000
> Set colServiceList = objWMIService.ExecQuery ("Select * from
> Win32_Service where Name=" & strService)
> For Each objService in colServiceList
> errReturn = objService.StopService()
> Next
> End Sub
> </code>
>
>

My System SpecsSystem Spec
Old 01-13-2009   #3 (permalink)
Joe Blow


 
 

Re: Starting & stopping services

Damn, I double apologize, my brain is not functioning this morning!

Let's just start over:

I found this code snippet that I am using, but would like some explanation
on a couple of points.

1. "StdOut", I only see where it is being set, but not used anywhere. What
is it, why would it be there (i.e. did I miss some other part of the snippet
possibly that uses it but I don't need it?).
2. When stopping the main service, it has errReturn =
objService.StopService(), but when the dependent services stop, it does
not...why?
3. What are the error return values equal to? I have found 4 so far in my
testing
a. 0 = Success (most likely)
b. 3 =
c. 5 =
d. 10 =

Thanks!

<code>
strComputer = "."
Set StdOut = WScript.StdOut
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
StopService "'EnterpriseVaultAdminService'"
Sub StopService(strService)
Set colServiceList = objWMIService.ExecQuery("Associators of _
{Win32_Service.Name=" & strService & "} _
Where AssocClass=Win32_DependentService Role=Antecedent")
For Each objService in colServiceList
objService.StopService()
Next
WScript.Sleep 10000
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service
_
where Name=" & strService)
For Each objService in colServiceList
errReturn = objService.StopService()
Next
End Sub
</code>


My System SpecsSystem Spec
Old 01-13-2009   #4 (permalink)
Jennifer


 
 

Re: Starting & stopping services

On Jan 13, 9:36*am, "Joe Blow" <j...@xxxxxx> wrote:
Quote:

> Damn, I double apologize, my brain is not functioning this morning!
>
> Let's just start over:
>
> I found this code snippet that I am using, but would like some explanation
> on a couple of points.
>
> 1. *"StdOut", I only see where it is being set, but not used anywhere. *What
> is it, why would it be there (i.e. did I miss some other part of the snippet
> possibly that uses it but I don't need it?).
> 2. *When stopping the main service, it has errReturn =
> objService.StopService(), but when the dependent services stop, it does
> not...why?
> 3. *What are the error return values equal to? *I have found 4 so farin my
> testing
> * a. *0 = Success (most likely)
> * b. *3 =
> * c. *5 =
> * d. *10 =
>
> Thanks!
>
> <code>
> strComputer = "."
> Set StdOut = WScript.StdOut
> Set objWMIService = GetObject("winmgmts:" & _
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> StopService "'EnterpriseVaultAdminService'"
> Sub StopService(strService)
> * Set colServiceList = objWMIService.ExecQuery("Associators of *_
> {Win32_Service.Name=" & strService & "} _
> Where AssocClass=Win32_DependentService Role=Antecedent")
> * For Each objService in colServiceList
> * * objService.StopService()
> * Next
> * WScript.Sleep 10000
> * Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service
> _
> where Name=" & strService)
> * For Each objService in colServiceList
> *errReturn = objService.StopService()
> * Next
> End Sub
> </code>
I don't see why you need the bit of code about StdOut.

The MSDN has a great page explaining all about the Stop Service
method:
http://msdn.microsoft.com/en-us/library/aa393673.aspx

I may be wrong, but I think that if you have a service that has
dependent services, then the dependent service must be stopped first.
Then you can try to stop the main service.

The return values for the StopService method are:

0 Success
1 Not Supported
2 Access Denied
3 Dependent Services Running
4 Invalid Service Control
5 Service Cannot Accept Control
6 Service Not Active
7 Service Request timeout
8 Unknown Failure
9 Path Not Found
10 Service Already Stopped
11 Service Database Locked
12 Service Dependency Deleted
13 Service Dependency Failure
14 Service Disabled
15 Service Logon Failed
16 Service Marked For Deletion
17 Service No Thread
18 Status Circular Dependency
19 Status Duplicate Name
20 Status - Invalid Name
21 Status - Invalid Parameter
22 Status - Invalid Service Account
23 Status - Service Exists
24 Service Already Paused

HTH,
Jennifer
My System SpecsSystem Spec
Old 01-13-2009   #5 (permalink)
Joe Blow


 
 

Re: Starting & stopping services


"Jennifer" <Scrabble.Devotee@xxxxxx> wrote in message
news:aabbfa58-7752-4746-b96c-c3466db596a3@xxxxxx
Quote:

> I don't see why you need the bit of code about StdOut.
>
> The MSDN has a great page explaining all about the Stop Service
> method:
> http://msdn.microsoft.com/en-us/library/aa393673.aspx
>
> I may be wrong, but I think that if you have a service that has
> dependent services, then the dependent service must be stopped first.
> Then you can try to stop the main service.
>
> The return values for the StopService method are:
>
> 0 Success
> 1 Not Supported
> 2 Access Denied
> 3 Dependent Services Running
> 4 Invalid Service Control
> 5 Service Cannot Accept Control
> 6 Service Not Active
> 7 Service Request timeout
> 8 Unknown Failure
> 9 Path Not Found
> 10 Service Already Stopped
> 11 Service Database Locked
> 12 Service Dependency Deleted
> 13 Service Dependency Failure
> 14 Service Disabled
> 15 Service Logon Failed
> 16 Service Marked For Deletion
> 17 Service No Thread
> 18 Status Circular Dependency
> 19 Status Duplicate Name
> 20 Status - Invalid Name
> 21 Status - Invalid Parameter
> 22 Status - Invalid Service Account
> 23 Status - Service Exists
> 24 Service Already Paused
>
> HTH,
> Jennifer
>
Thanks Jennifer! That does help. I already commented out the StdOut and
the script works fine without it, I was more curious what it was for, I'll
google some more for it but couldn't really find anything definitive.

I am also stopping the dependencies first. Thanks for the link and the
return values, that will help me ensure things work right.

Joe


My System SpecsSystem Spec
Old 01-13-2009   #6 (permalink)
Pegasus \(MVP\)


 
 

Re: Starting & stopping services


"Joe Blow" <joe@xxxxxx> wrote in message
news:uBq3dGadJHA.1860@xxxxxx
Quote:

>
> "Jennifer" <Scrabble.Devotee@xxxxxx> wrote in message
> news:aabbfa58-7752-4746-b96c-c3466db596a3@xxxxxx
>
Quote:

>> I don't see why you need the bit of code about StdOut.
>>
>> The MSDN has a great page explaining all about the Stop Service
>> method:
>> http://msdn.microsoft.com/en-us/library/aa393673.aspx
>>
>> I may be wrong, but I think that if you have a service that has
>> dependent services, then the dependent service must be stopped first.
>> Then you can try to stop the main service.
>>
>> The return values for the StopService method are:
>>
>> 0 Success
>> 1 Not Supported
>> 2 Access Denied
>> 3 Dependent Services Running
>> 4 Invalid Service Control
>> 5 Service Cannot Accept Control
>> 6 Service Not Active
>> 7 Service Request timeout
>> 8 Unknown Failure
>> 9 Path Not Found
>> 10 Service Already Stopped
>> 11 Service Database Locked
>> 12 Service Dependency Deleted
>> 13 Service Dependency Failure
>> 14 Service Disabled
>> 15 Service Logon Failed
>> 16 Service Marked For Deletion
>> 17 Service No Thread
>> 18 Status Circular Dependency
>> 19 Status Duplicate Name
>> 20 Status - Invalid Name
>> 21 Status - Invalid Parameter
>> 22 Status - Invalid Service Account
>> 23 Status - Service Exists
>> 24 Service Already Paused
>>
>> HTH,
>> Jennifer
>>
> Thanks Jennifer! That does help. I already commented out the StdOut and
> the script works fine without it, I was more curious what it was for, I'll
> google some more for it but couldn't really find anything definitive.
>
> I am also stopping the dependencies first. Thanks for the link and the
> return values, that will help me ensure things work right.
>
> Joe
Console commands can pick up two output streams: Standard Output and Error
Output. The syntax goes like so:

cscript //nologo c:\Joe.vbs 1>c:\standard.txt 2>c:\error.txt

When your script writes lines of text to StdOut then they will end up in
c:\standard.txt. This is a universal method used by lots of operating
systems.


My System SpecsSystem Spec
Old 01-13-2009   #7 (permalink)
Joe Blow


 
 

Re: Starting & stopping services


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:ujwMQhadJHA.1328@xxxxxx
Quote:

>
> Console commands can pick up two output streams: Standard Output and Error
> Output. The syntax goes like so:
>
> cscript //nologo c:\Joe.vbs 1>c:\standard.txt 2>c:\error.txt
>
> When your script writes lines of text to StdOut then they will end up in
> c:\standard.txt. This is a universal method used by lots of operating
> systems.
That's cool, thanks Pegasus! So by the same logic, could you write lines to
"ErrOut"?

Then, what happens if you don't give it a redirect place? Does it just
ignore it?

j


My System SpecsSystem Spec
Old 01-13-2009   #8 (permalink)
Pegasus \(MVP\)


 
 

Re: Starting & stopping services


"Joe Blow" <joe@xxxxxx> wrote in message
news:evEDHuadJHA.4600@xxxxxx
Quote:

>
> "Pegasus (MVP)" <I.can@xxxxxx> wrote in message
> news:ujwMQhadJHA.1328@xxxxxx
Quote:

>>
>> Console commands can pick up two output streams: Standard Output and
>> Error Output. The syntax goes like so:
>>
>> cscript //nologo c:\Joe.vbs 1>c:\standard.txt 2>c:\error.txt
>>
>> When your script writes lines of text to StdOut then they will end up in
>> c:\standard.txt. This is a universal method used by lots of operating
>> systems.
>
> That's cool, thanks Pegasus! So by the same logic, could you write lines
> to "ErrOut"?
Sure can - that's the essence of the whole thing?
Quote:

> Then, what happens if you don't give it a redirect place? Does it just
> ignore it?
It goes to the console (=screen). You should actually give it a try so that
you can see for yourself . . .


My System SpecsSystem Spec
Old 01-13-2009   #9 (permalink)
Joe Blow


 
 

Re: Starting & stopping services


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:OetPoUbdJHA.2112@xxxxxx
Quote:

>
Quote:

>> That's cool, thanks Pegasus! So by the same logic, could you write lines
>> to "ErrOut"?
>
> Sure can - that's the essence of the whole thing?
>
Quote:

>> Then, what happens if you don't give it a redirect place? Does it just
>> ignore it?
>
> It goes to the console (=screen). You should actually give it a try so
> that you can see for yourself . . .
I will, when I have time...not necessary for my current project.

Thanks for the pointers, much appreciated!



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Self starting and stopping torrent software Software
How to make a batch file on starting and stopping services from command prompt ? General Discussion
stopping and starting service PowerShell
stopping a program from starting up Vista General
Get-WmiObject and starting/stopping remote services PowerShell


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