SunQuest
 
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
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  
Old October 15th, 2004, 08:19 PM
ranshe ranshe is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 ranshe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question How to Start and Stop Window's Services

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.

Reply With Quote
  #2  
Old October 17th, 2004, 01:06 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 33 m 48 sec
Reputation Power: 180
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

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > How to Start and Stop Window's Services


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway