Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to disable/ enable devices from the device-manager with WSH-script?

4 views
Skip to first unread message

Winston

unread,
Dec 13, 2002, 6:04:11 AM12/13/02
to
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.

Thx for help,
Winston

CJ Morton

unread,
Dec 13, 2002, 11:43:17 AM12/13/02
to
Check out device.vbs from the Windows 2000 Resource Kit.

CJ M

"Winston" <winsto...@gmx.net> wrote in message
news:uIbOadpoCHA.1236@TK2MSFTNGP12...

Torgeir Bakken (MVP)

unread,
Dec 13, 2002, 12:08:17 PM12/13/02
to
Winston wrote:

> 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


Torgeir Bakken (MVP)

unread,
Dec 13, 2002, 9:49:24 AM12/13/02
to
Winston wrote:

> 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

Winston

unread,
Dec 16, 2002, 3:25:01 AM12/16/02
to
I found a command-line tool named DevCon which does exaclty what I want. I
can use it in my script, too.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;311272

Winston

"Winston" <winsto...@gmx.net> wrote in message
news:uIbOadpoCHA.1236@TK2MSFTNGP12...

0 new messages