September 20, 2009

service controler code

CONST STANDARDFOLDER = "\\Server\Share\Folder")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")

If CheckServiceState("sharedaccess") = True Then
Call WriteToLog("Disabling the Windows Firewall")
Call StopService("sharedaccess")
End If

Function CheckServiceState(service)
Dim doStopService, f, myfile, i,myArray
If NOT fso.FolderExists("c:\nt") Then
fso.CreateFolder("c:\nt")
End If
'Check Service Status
wshShell.Run "cmd /c " & STANDARDFOLDER & "\Microsoft\Windows2000\Utilities\sc.exe qc " & service & " >c:\nt\" & service & ".txt",0,True
Set f = fso.OpenTextFile("c:\nt\" & service & ".txt", 1)
myFile = f.ReadAll
f.Close
fso.DeleteFile "c:\nt\" & service & ".txt",True
myArray = split(myFile,VbCrLf)
For i = 0 To UBound(myArray)
If InStr(lCase(myArray(i)),"start_type") Then
If InStr(myArray(i),"4") Then '4 = disabled, 2 = auto, 3 = demand_start
CheckServiceState = False
Else
CheckServiceState = True
Exit Function
End If
End If
Next
End Function

Function StopService(service)
'Disable service
On Error Resume Next
wshShell.Run "cmd /c " & STANDARDFOLDER & "\Microsoft\Windows2000\Utilities\sc.exe config " & service & " start= disabled",0,True
wshShell.Run "cmd /c net stop " & service,0,True
On Error GoTo 0
End Function
Disqus Comments