我有一个任务,不知道如何解决它!禁用使用光盘驱动器(VB.NET)
基本上,我想禁用PC上的CD驱动器,所以我们的用户不能使用它们。
这就是我想要开始的方式 - 最终我想要一个系统托盘中的图标,允许您锁定和解锁CD驱动器并提供您知道的密码。
我需要开始的地方,但有人知道如何禁用在VB.net中使用的CD驱动器?
任何帮助,将不胜感激。
安德鲁
我有一个任务,不知道如何解决它!禁用使用光盘驱动器(VB.NET)
基本上,我想禁用PC上的CD驱动器,所以我们的用户不能使用它们。
这就是我想要开始的方式 - 最终我想要一个系统托盘中的图标,允许您锁定和解锁CD驱动器并提供您知道的密码。
我需要开始的地方,但有人知道如何禁用在VB.net中使用的CD驱动器?
任何帮助,将不胜感激。
安德鲁
我找到了一种方法来做到这一点。
基本上我需要依次通过在设备管理器中的所有项目是这样的:
search = New System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity")
For Each info In search.Get()
' Go through each device detected.
Next
我然后拿着的DeviceID和ClassGuid部分。
如果Guid与CD/DVD播放机的GUID匹配{4D36E965-E325-11CE-BFC1-08002BE10318},我告诉它禁用/启用取决于用户想要做什么的设备。
要启用或禁用它们,我发现这个方便的程序都准备好去from here。
然后,我只不过是编辑Form1.vb的是:
Imports System.Management
公共类Form1中
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
末级
这也就那么通过在设备管理器中的CD/DVD驱动器环路和禁用/启用它们。
我还没有整理代码 - 我需要将脚本作为一个线程来运行,因为它在执行它的时候会挂起。
我还打算让程序计算出CD驱动器在使用计时器事件时的状态 - 然后相应地报告回来......然后我需要让它在没有窗体的系统托盘中运行,最后让它像运行桌面交互的LSA一样运行。
当我得到片刻时,我会完成它 - 但你需要的一切应该在这里。
希望这可以帮助别人一点点!
我在想,有一种方法可能是禁用设备管理器中的设备 - 只需禁用DVD/CD-ROM中的所有条目......但我该怎么做? – 2010-02-15 16:27:55