Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a service

Status
Not open for further replies.
Mar 18, 2002
12
US
I'm new to VBScript and am looking for a way to read the regisitry to determine if the spooler service is set to manual or disabled. My code looks like this:

Dim WshShell, bKey
Set WshShell = WScript.CreateObject("WScript.Shell")

bKey = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Spooler\")
WScript.Echo WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Spooler\Start")

I get an error message saying the key can't be opened for reading. How can I get this to work?

Thanks
 
obiwantuxedo,

Try this..

fengshui_1998

' -------------------

Dim ServerName
Dim ServiceSet
Dim Service
Dim svcState

'class Win32_Service : Win32_BaseService
'{
' boolean AcceptPause ;
' boolean AcceptStop ;
' string Caption ;
' uint32 CheckPoint ;
' string CreationClassName ;
' string Description ;
' boolean DesktopInteract ;
' string DisplayName ;
' string ErrorControl ;
' uint32 ExitCode ;
' datetime InstallDate ;
' string Name ;
' string PathName ;
' uint32 ProcessId ;
' uint32 ServiceSpecificExitCode ;
' string ServiceType ;
' boolean Started ;
' string StartMode ;
' string StartName ;
' string State ;
' string Status ;
' string SystemCreationClassName ;
' string SystemName ;
' uint32 TagId ;
' uint32 WaitHint ;
'};


ServerName = InputBox("Enter the name of the Server> ")

Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & servername).ExecQuery("select * from Win32_Service")

For each Service in ServiceSet

WScript.Echo Service.Description & " is " & Service.StartMode

If Service.State = "Running" Then 'Wscript.Echo Service.State
prompt = Service.Description & " is running, Would you like to stop this service? "
svcState = msgBox(prompt, vbYesNoCancel)

If svcState = vbYes Then
msgbox "Stopping " & Service.Description
Service.StopService()

ElseIf svcState = vbCancel Then
Exit For
Else
End If
End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top