Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found a way to do this.</p> <p>Basically I needed to loop through all the items in the device manager like this:</p> <pre><code>search = New System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity") For Each info In search.Get() ' Go through each device detected. Next </code></pre> <p>I then took the DeviceID and ClassGuid sections.</p> <p>If the Guid matched {4D36E965-E325-11CE-BFC1-08002BE10318} which is the GUID for a CD/DVD player, I told it to disable/enable the device dependent on what the user wanted to do.</p> <p>To enable or disable them, I found this handy program all ready to go <a href="http://jo0ls-dotnet-stuff.blogspot.com/2009/01/enabledisable-device-programmatically.html" rel="nofollow noreferrer">from here</a> .</p> <p>I then simply edited Form1.vb this:</p> <pre><code>Imports System.Management </code></pre> <p>Public Class Form1</p> <pre><code>Private Sub btnEnable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnable.Click getCdDrives("Enable") End Sub Private Sub btnDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisable.Click getCdDrives("Diable") End Sub Public Function getCdDrives(ByVal EnableOrDisable As String) As Boolean If InputBox("password") = "password" Then Try Dim info As System.Management.ManagementObject Dim search As System.Management.ManagementObjectSearcher Dim deviceGuid As String Dim deviceType As String Dim cameraIsSeenByWindows As Boolean = False Dim showDebugPrompts As Boolean = False Dim actualGuid As Guid search = New System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity") For Each info In search.Get() ' Go through each device detected. deviceType = CType(info("DeviceID"), String) deviceGuid = CType(info("ClassGuid"), String) If deviceGuid = "{4D36E965-E325-11CE-BFC1-08002BE10318}" Then actualGuid = New Guid(deviceGuid) If EnableOrDisable = "Enable" Then DeviceHelper.SetDeviceEnabled(actualGuid, deviceType, True) Else DeviceHelper.SetDeviceEnabled(actualGuid, deviceType, False) End If End If Next If EnableOrDisable = "Enable" Then btnDisable.Enabled = True btnEnable.Enabled = False Else btnDisable.Enabled = False btnEnable.Enabled = True End If Catch ex As Exception MsgBox(ex.Message) End Try Else MsgBox("Oooh Va Vu!!") End If End Function </code></pre> <p>End Class</p> <p>That will then loop through the CD/DVD drives in device manager and disable/enable them.</p> <p>I have yet to tidy the code up - and I need to run the script as a thread because it hangs at the moment while it's doing it's thing.</p> <p>I also intend to get the program to work out what state the CD drives are in using a timer event - and then report back accordingly... I then need to get it to run in the system tray with no form and finally get it to run as the LSA with desktop interaction enabled.</p> <p>I'll finish it when I get a moment - but everything you need should be here.</p> <p>Hope this helps someone out a bit!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload