本文介绍了我如何使用Vb.Net禁用或启用Usbstor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Imports Microsoft.Win32 Public 类 Form1 私有 Sub Button1_Click( ByVal 发​​件人作为 对象, ByVal e As System.EventArgs)句柄 Button1.Click Dim regKey As RegistryKey ' 从regedit打开USBSTOR路径 如果 RadioButton1.Checked 然后 如果 MsgBox( 除了当前连接的端口(例如,USB鼠标,打印机等!)之外,所有USB端口都将被禁用,MsgBoxStyle.OkCancel, 你确定吗?!)= MsgBoxResult.Ok 然后 regKey = Registry.LocalMachine。 OpenSubKey( SYSTEM \ CurrentControlSet \ Services \ USBSTOR, True ) regKey.SetValue( Start, 4 )' 4(禁用端口) 结束 如果 Else regKey = Registry.LocalMachine.OpenSubKey( SYSTEM \ CurrentControlSet \ Services \USBSTOR, True ) regKey.SetValue( 开始, 3 )' 3(启用端口) MsgBox( 端口已启用!,MsgBoxStyle.OkOnly) 结束 如果 结束 Sub 结束 类 我这样做了Bt我运行应用程序时出现以下声明错误 regKey = Registry.LocalMachine.OpenSubKey( SYSTEM \\ CurrentControlSet \ Services \USBSTOR ,True) 请有人帮我纠正这个错误...或有人请开发示例程序并发送源代码请帮助我..谢谢解决方案 请阅读我对该问题的评论。 您需要具有管理员权限才能修改操作系统注册表。要解决此问题,请使用 DevCon命令 [ ^ ]。以下是C#中的示例: http://programmersheaven.com/discussion/ 337951 / programatically-enable - disable-usb-port-using-cnet [ ^ ] 设备控制台(DevCon.exe)示例 [ ^ ] Imports Microsoft.Win32Public Class Form1 Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim regKey As RegistryKey 'opens the path USBSTOR from regedit If RadioButton1.Checked Then If MsgBox("All USB Ports Will Be Disabled Except The Presently Connected Ports (Ex.,USB Mouse,Printer etc !) ", MsgBoxStyle.OkCancel, "ARE YOU SURE ?!") = MsgBoxResult.Ok Then regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True) regKey.SetValue("Start", 4) ' 4(To disable the ports) End If Else regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True) regKey.SetValue("Start", 3) ' 3(To enable the ports) MsgBox("Ports Are Enabled !", MsgBoxStyle.OkOnly) End If End SubEnd ClassI done this Bt i got a error on the below statement while run the application"regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True)"please someone help me to correct this error... or someone please devlop a sample program and send the sourcecode please help me.. Thank You 解决方案 Please, read my comment to the question.You need to have admin privileges to be able to modify OS registry. To work around it, use DevCon command[^]. Here is an example in C#: http://programmersheaven.com/discussion/337951/programatically-enable--disable-usb-port-using-cnet[^]Device Console (DevCon.exe) Examples[^] 这篇关于我如何使用Vb.Net禁用或启用Usbstor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-16 08:21