Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - VBScript
Blog
 
# Wednesday, December 09, 2009

This is the code, which you will use for stop Services using VBS Script

Function StopServices
 Dim objWMIService,colItems,ObjItem,chkServiceStatus,RetVal
 Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
 Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where name='" & strServiceName & "'",,48)
 For Each ObjItem in colItems
  If (InStr (1,objItem.DisplayName,strServiceName,1) > 0) then
   chkServiceStatus=ObjItem.State
  end if
 Next

 If(ucase(chkServiceStatus)="RUNNING") THEN
  RetVal = goShell.Run("%windir%\system32\sc.exe Stop """ & strServiceName & """ >> " & gcsLogFile,0,True)
   Do Until(Ucase(ServiceStatus)="STOPPED")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where name='" & strServiceName & "'",,48)
    For Each ObjItem in colItems
     If (InStr (1,objItem.DisplayName,strServiceName,1) > 0) then
      ServiceStatus=ObjItem.State
     end if
    Next 
   Loop 
 End If


 
End Function

Wednesday, December 09, 2009 11:43:06 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   VB Script  | 
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: