Discussion:
Can I use WMI (C#) to disable/enable a device?
(too old to reply)
Michael
2006-07-20 00:38:18 UTC
Permalink
I'm exploring how to programmatically disable/enable devices in a system
using C#.


-MH
Willy Denoyette [MVP]
2006-08-03 08:26:57 UTC
Permalink
No, this is not provided through WMI, all you can do is stop and start the
(device driver) service (provided the device is startable/stoppable), take a
look at the Win32_SystemDriver class and it's StartService and StopService
commands.


Willy.

"Michael" <***@domain.com> wrote in message news:%***@TK2MSFTNGP05.phx.gbl...
| I'm exploring how to programmatically disable/enable devices in a system
| using C#.
|
|
| -MH
|
|
mabra
2006-08-04 09:28:23 UTC
Permalink
Hi Willy and All,

I feel, you're probably wrong. The "Win32_SystemDriver"
class has a "ChangeStartMode" method.
I scripted, years ago, the following:

Set objLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set objServices = objLocator.ConnectServer(".", "root/CIMV2")
strWMIObjectID = "Win32_SystemDriver.Name=""Cdrom""" 'Be excact here!
Set objService = objServices.Get(strWMIObjectID)
objService.ChangeStartMode strStartMode

This will become active, after the box re-starts.
I think, the same method should o in C# ;-)

Best regards,
Manfred
Post by Willy Denoyette [MVP]
No, this is not provided through WMI, all you can do is stop and start the
(device driver) service (provided the device is startable/stoppable), take a
look at the Win32_SystemDriver class and it's StartService and StopService
commands.
Willy.
| I'm exploring how to programmatically disable/enable devices in a system
| using C#.
|
|
| -MH
|
|
Willy Denoyette [MVP]
2006-08-19 09:50:00 UTC
Permalink
Right, but this is not what the OP was asking about. The OP asked if it was
possible to programatically enable/disable a device, what you are suggesting
is changing the startmode, but this only takes effect after a reboot, which
is IMO not what the OP is looking for. Note also that it highly depends on
the device, some do not allow to change the startmode and others simply
ignore it.

Willy.


"mabra" <***@home> wrote in message news:%23p4P$***@TK2MSFTNGP06.phx.gbl...
| Hi Willy and All,
|
| I feel, you're probably wrong. The "Win32_SystemDriver"
| class has a "ChangeStartMode" method.
| I scripted, years ago, the following:
|
| Set objLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
| Set objServices = objLocator.ConnectServer(".", "root/CIMV2")
| strWMIObjectID = "Win32_SystemDriver.Name=""Cdrom""" 'Be excact here!
| Set objService = objServices.Get(strWMIObjectID)
| objService.ChangeStartMode strStartMode
|
| This will become active, after the box re-starts.
| I think, the same method should o in C# ;-)
|
| Best regards,
| Manfred
|
| Willy Denoyette [MVP] wrote:
| > No, this is not provided through WMI, all you can do is stop and start
the
| > (device driver) service (provided the device is startable/stoppable),
take a
| > look at the Win32_SystemDriver class and it's StartService and
StopService
| > commands.
| >
| >
| > Willy.
| >
| > "Michael" <***@domain.com> wrote in message
| > news:%***@TK2MSFTNGP05.phx.gbl...
| > | I'm exploring how to programmatically disable/enable devices in a
system
| > | using C#.
| > |
| > |
| > | -MH
| > |
| > |
| >
| >
mabra
2006-08-19 10:51:44 UTC
Permalink
Hi Willy,

sorry, I don't saw the difference ..... ;-)

Best regards,
Manfred
Post by Willy Denoyette [MVP]
Right, but this is not what the OP was asking about. The OP asked if it was
possible to programatically enable/disable a device, what you are suggesting
is changing the startmode, but this only takes effect after a reboot, which
is IMO not what the OP is looking for. Note also that it highly depends on
the device, some do not allow to change the startmode and others simply
ignore it.
Willy.
| Hi Willy and All,
|
| I feel, you're probably wrong. The "Win32_SystemDriver"
| class has a "ChangeStartMode" method.
|
| Set objLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
| Set objServices = objLocator.ConnectServer(".", "root/CIMV2")
| strWMIObjectID = "Win32_SystemDriver.Name=""Cdrom""" 'Be excact here!
| Set objService = objServices.Get(strWMIObjectID)
| objService.ChangeStartMode strStartMode
|
| This will become active, after the box re-starts.
| I think, the same method should o in C# ;-)
|
| Best regards,
| Manfred
|
| > No, this is not provided through WMI, all you can do is stop and start
the
| > (device driver) service (provided the device is startable/stoppable),
take a
| > look at the Win32_SystemDriver class and it's StartService and
StopService
| > commands.
| >
| >
| > Willy.
| >
| > | I'm exploring how to programmatically disable/enable devices in a
system
| > | using C#.
| > |
| > |
| > | -MH
| > |
| > |
| >
| >
Loading...