【问题标题】:Disable the use of CD drive (VB.NET)禁用 CD 驱动器 (VB.NET)
【发布时间】:2010-02-15 12:34:55
【问题描述】:

我有一个任务,不知道如何解决它!

基本上,我想禁用 PC 上的 CD 驱动器,以便我们的用户无法使用它们。

无论如何,这就是我想要开始的方式 - 最终,我希望系统托盘中有一个图标,允许在您知道密码的情况下锁定和解锁 CD 驱动器。

我需要从某个地方开始 - 有谁知道如何在 VB.net 中禁用 CD 驱动器的使用?

任何帮助将不胜感激。

安德鲁

【问题讨论】:

  • 我认为一种方法可能是在设备管理器中禁用该设备 - 只需禁用 DVD/CD-ROM 部分中的所有条目...但我该怎么做呢?

标签: vb.net cd


【解决方案1】:

我找到了一种方法。

基本上我需要像这样遍历设备管理器中的所有项目:

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

公开课表1

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 运行。

我会在我有时间的时候完成它 - 但你需要的一切都应该在这里。

希望这对某人有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    • 2019-11-02
    • 2019-03-10
    • 1970-01-01
    • 2012-09-07
    • 2015-12-24
    • 2017-11-29
    相关资源
    最近更新 更多