![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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> 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 Specs![]() |
| | #5 (permalink) |
| | 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 > 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 Specs![]() |
| | #6 (permalink) |
| | 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 >> > 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 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 Specs![]() |
| | #7 (permalink) |
| | 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. "ErrOut"? Then, what happens if you don't give it a redirect place? Does it just ignore it? j |
My System Specs![]() |
| | #8 (permalink) |
| | 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"? Quote: > Then, what happens if you don't give it a redirect place? Does it just > ignore it? you can see for yourself . . . |
My System Specs![]() |
| | #9 (permalink) |
| | 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 . . . Thanks for the pointers, much appreciated! |
My System Specs![]() |
![]() |
| 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 | |||