Thx for help,
Winston
CJ M
"Winston" <winsto...@gmx.net> wrote in message
news:uIbOadpoCHA.1236@TK2MSFTNGP12...
> is it possible to disable and/or enable devices from the w2k-device-manager
> with a WSH-script (in my case in JScript)? An unattendend mode would be
> nice.
Hi
You can use ADSI for this, here is a vbscript example:
sComputer = "." ' "." for local machine
sService = "Fax"
bOK = EnableAndStartService(sService, sComputer)
If bOK Then
WScript.Echo sService & " enabled and started"
Else
WScript.Echo "Failed to enable and start " & sService
End If
bOK = StopAndDisableService(sService, sComputer)
If bOK Then
WScript.Echo sService & " disabled and stopped"
Else
WScript.Echo "Failed to disable and stop " & sService
End If
Function EnableAndStartService(sService, sNode)
Const ADS_SERVICE_STOPPED = 1
Const ADS_SERVICE_RUNNING = 4
Const ADS_SERVICE_DISABLED = 4
Const ADS_SERVICE_AUTO_START = 2
Const ADS_SERVICE_DEMAND_START = 3
Dim oComputer, oService
Set oComputer = GetObject("WinNT://" & sNode & ",computer")
On Error Resume Next
Set oService = oComputer.GetObject("Service", sService)
If Err.Number <> 0 Then
EnableAndStartService = False
Exit Function
End If
If oService.StartType = ADS_SERVICE_DISABLED Then
oService.StartType = ADS_SERVICE_DEMAND_START
oService.SetInfo
WScript.Sleep 1000
End If
If oService.Status <> ADS_SERVICE_RUNNING Then
oService.Start
WScript.Sleep 1000
End If
EnableAndStartService = True
End Function
Function StopAndDisableService(sService, sNode)
Const ADS_SERVICE_STOPPED = 1
Const ADS_SERVICE_RUNNING = 4
Const ADS_SERVICE_DISABLED = 4
Const ADS_SERVICE_AUTO_START = 2
Const ADS_SERVICE_DEMAND_START = 3
Dim oComputer, oService
Set oComputer = GetObject("WinNT://" & sNode & ",computer")
On Error Resume Next
Set oService = oComputer.GetObject("Service", sService)
If Err.Number <> 0 Then
StopAndDisableService = False
Exit Function
End If
If oService.StartType <> ADS_SERVICE_DISABLED Then
oService.StartType = ADS_SERVICE_DISABLED
oService.SetInfo
WScript.Sleep 1000
End If
If oService.Status <> ADS_SERVICE_STOPPED Then
oService.Stop
WScript.Sleep 1000
End If
StopAndDisableService = True
End Function
--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway
> Hi Group,
> is it possible to disable and/or enable devices from the w2k-device-manager
> with a WSH-script (in my case in JScript)? An unattendend mode would be
> nice.
Hi
http://support.microsoft.com/default.aspx?scid=kb;EN-US;311272
Winston
"Winston" <winsto...@gmx.net> wrote in message
news:uIbOadpoCHA.1236@TK2MSFTNGP12...