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:
This code was referenced in thread707-930084; The reference was in the 3rd response of this thread(from PVS).
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
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 line
got the following error message:
[COLOR=red yellow]
Run-time error
'-2147217406(80041002)':
Automation error[/color]
On the error line, in debug, the "objService" would be "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.
Thanks!
I have been testing some code from the "MS 2000 Scripting Guide". Its link is:
This code was referenced in thread707-930084; The reference was in the 3rd response of this thread(from PVS).
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 line
Code:
For Each objService in colServiceList
[COLOR=red yellow]
Run-time error
'-2147217406(80041002)':
Automation error[/color]
On the error line, in debug, the "objService" would be "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.
Thanks!