|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
I need help on getting the following code to run!
I have been testing some code from the "MS 2000 Scripting Guide". Its link is: http://www.microsoft.com/resources/documentation/w... The web site code with its preceding comments is as follows: Scripting Steps The scripts for stopping and starting dependent services perform similar steps but in the opposite order Stopping dependent services Listing 15.16 contains a script that stops the IIS Admin Service and all its dependents. To carry out this task, the script must perform the following steps: 1. Create a variable to specify the computer name. 2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate." 3. Use the ExecQuery method to query the Win32_Service class. This query must use an Associators of query and specify the following information: • The instance of the service on which the query is performed (Win32_Service.Name = 'IISAdmin'). • The name of the Association class (AssocClass = Win32_DependentService). If the class name is not specified, the query returns all associated classes and their instances. • The role played by the IISAdmin Service. In this case, IISAdmin is Antecedent to the services to be returned by the query. The query returns a collection consisting of all the services dependent on the IIS Admin Service. 4. For each service in the collection, use the StopService method to stop the service. 5. After a stop control has been sent to each dependent service, pause for 60 seconds (60,000 milliseconds) to give the SCM time to stop each service. 6. Use a the ExecQuery method to retrieve the instance of the IISAdmin Service. 7. Use the StopService method to stop the IISAdmin Service. Listing 15.16 Stopping a Service and Its Dependents CODE: strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Service.Name='iisadmin'} WHERE " _ & "AssocClass=Win32_DependentService Role=Antecedent" ) For Each objService in colServiceList errReturn = objService.StopService() Next Wscript.Sleep 60000 Set colServiceList = objWMIService.ExecQuery _ ("SELECT * FROM Win32_Service WHERE Name='iisadmin'") For Each objService in colServiceList errReturn = objService.StopService() Next I did not include the Start Services proceedure. The Problem I am having: Since I do not have the service 'iisadmin' I switched it in my test code to 'DHCP Client' (which, by the way, has no Dependent Services but I tested it on others that did). When I ran the code the first occurrance of the following code line "For Each objService in colServiceList" got the following error message: Run-time error '-2147217406(80041002)': Automation error On the error line, in debug, the "objService" was "empty" when hovered over by the mouse pointer. In my debugging process I tried to comment out various portions of code and other such things to no avail. I also tried to read up on the problem at the link and other places without success. I would greatly appreciate help on how to get this to run. |
|
#2
|
|||
|
|||
|
If you have VB6 you might try this code from a new exe project. There you'll have a good debugger to help identify the source of the error.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > How to Start and Stop Window's Services |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|