禁用 CD 驱动器 (VB.NET)

发布于 2024-08-21 18:35:57 字数 218 浏览 8 评论 0原文

我有一个任务,但不知道如何处理它!

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

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

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

任何帮助将不胜感激。

安德鲁

I have a task and no idea how to tackle it!

Basically, I want to disable the CD drive on a PC so our users can't use them.

That's how I want to start anyway - ultimately I'd like an icon in the system tray that allows the CD drive(s) to be locked and unlocked providing you know a password.

I need somewhere to start though - does anyone know how to disable the use of a CD drive in VB.net?

Any help would be appreciated.

Andrew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生不灭 2024-08-28 18:35:57

我找到了一种方法来做到这一点。

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

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} 匹配,我会告诉它根据用户想要执行的操作禁用/启用设备。

要启用或禁用它们,我发现这个方便的程序已准备就绪 从这里

然后,我简单地编辑了 Form1.vb:

Imports System.Management

Public Class 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

End Class

然后将循环遍历设备管理器中的 CD/DVD 驱动器并禁用/启用它们。

我还没有整理代码 - 我需要将脚本作为线程运行,因为它在执行操作时挂起。

我还打算让程序使用计时器事件计算出 CD 驱动器处于什么状态 - 然后相应地报告...然后我需要让它在没有表单的系统托盘中运行,最后让它到作为启用桌面交互的 LSA 运行。

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

希望这对某人有所帮助!

I found a way to do this.

Basically I needed to loop through all the items in the device manager like this:

search = New System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity")
            For Each info In search.Get()
                ' Go through each device detected.
            Next

I then took the DeviceID and ClassGuid sections.

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.

To enable or disable them, I found this handy program all ready to go from here .

I then simply edited Form1.vb this:

Imports System.Management

Public Class 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

End Class

That will then loop through the CD/DVD drives in device manager and disable/enable them.

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.

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.

I'll finish it when I get a moment - but everything you need should be here.

Hope this helps someone out a bit!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文