Starting and stopping Services from ASP or VBS 
Author Message
 Starting and stopping Services from ASP or VBS

Hi.
How can I get the same control over Nt/Win2000 Services in VBS like the NET
START/STOP commands.
I found a code (se below ) that gives me a list of all services but I don't
know how to controll them.
Can anybody help me here.
Regards
Oskar H.

'********************************************************************
'* File:        services.vbs
'* Purpose:     display service information on a computer using WMI
'* Requires:    WMI to be installed on server specified
'* Revisions:   Initial development - 01/08/01, tonymu
'* Disclaimer:  This code is to be used for sample purposes only
'*              Microsoft does not guarantee its functionality
'********************************************************************
Dim oArgs, strServerName, oServiceSet, oWshNetwork
Set oArgs = WScript.Arguments
If oArgs.Count > 0 Then
   strServerName = trim(oArgs(0))
Else
   strServerName = "LocalHost"
End If
Set oServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" &
strServerName & "/root/cimv2").InstancesOf("Win32_Service")
If strServerName = "LocalHost" Then
   Set oWshNetwork = WScript.CreateObject("WScript.Network")
   WScript.Echo "Service Information retrieved from " &
oWshNetwork.ComputerName
   Set oWshNetwork = Nothing
Else
   WScript.Echo "Service Information retrieved from " & strServerName
End If
WScript.Echo String(75, "_")
For each Service in oServiceSet
 WScript.Echo
 WScript.Echo "   " & Service.Description
 WScript.Echo "      Short Name:    " & Service.Name
 WScript.Echo "      Current State: " & Service.State
Next
WScript.Echo String(75, "_")
Set oServiceSet = Nothing



Mon, 16 Feb 2004 08:35:02 GMT  
 Starting and stopping Services from ASP or VBS

Quote:

> Hi.
> How can I get the same control over Nt/Win2000 Services in VBS like the NET
> START/STOP commands.
> I found a code (se below ) that gives me a list of all services but I don't
> know how to controll them.
> Can anybody help me here.

Win32_Service
http://msdn.microsoft.com/library/en-us/wmisdk/hh/wmisdk/r_32os_4dyd.asp

I also **highly** recommend Marcin Policht's new book

WMI Essentials for Automating Windows Management
http://www.softpro.com/0-672-32144-0.html

got mine from www.fatbrain.com ;-)...

--

Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--



Mon, 16 Feb 2004 09:49:09 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. stop/start a service in VBS

2. Starting and Stopping NT Services from WSH/VBS

3. START/STOP/ displayed Services running on PC thu an ASP page

4. ASP Service Stopping and Starting

5. Starting, stopping and pauseing a service.

6. Problems with stopping/starting service

7. How to start/stop services with vbscript?

8. How to start/stop a NT service

9. start and stop services

10. login script to start/stop service

11. Stop and Starting Services on NT

12. Starting and Stopping NT Services with ADSI,wsh, and VBScript

 

 
Powered by phpBB® Forum Software