以编程方式禁用USB设备。 [英] Disable USB devices programmatically.
本文介绍了以编程方式禁用USB设备。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我想在我的电脑上使用应用程序C#.net禁用USB设备。
这样做,使用API函数SetupDiSetClassInstallParams和SetupDiCallClassInstaller。
SetupDiSetClassInstallParams工作正常,但SetupDiSetClassInstallParams返回False,错误代码为0. [Windows 7 32位]
请帮帮我
谢谢
[edit]仅限主题 - OriginalGriff [/ edit]
hello
I want Disable USB devices on my pc with application C#.net.
for do it ,use API functions SetupDiSetClassInstallParams and SetupDiCallClassInstaller.
SetupDiSetClassInstallParams work fine but SetupDiSetClassInstallParams return False with error code 0.[Windows 7 32 bits]
Please help me
thanks
[edit]Subject only - OriginalGriff[/edit]
推荐答案
我需要使用c#禁用计算机的USB端口。 />
以下是适用于32位窗口但不能正常工作的解决方案...我需要一个相同的功能,它可以为64位做同样的事情... 。
//禁用USB存储...
Microsoft.Win32.Registry.SetValue(@HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services'\\USBSTOR,Start,4,Microsoft.Win32.RegistryValueKind.DWord);
//启用USB存储...
Micr osoft.Win32.Registry.SetValue(@HKEY_LOCAL_MACHINE \SYSTEM \ CurrentControlSet \ Services \ USBSTOR,Start,3,Microsoft.Win32.RegistryValueKind.DWord);
i可以读取Windows 64位上的值,但无法写入值....
RegistryKey registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine,RegistryView.Registry64 );
Console.WriteLine(registryKey+ registryKey);
registryKey = registryKey.OpenSubKey(@SYSTEM\CurrentControlSet\Services\USBSTOR);
Object val = registryKey.GetValue(Start);
Console.WriteLine(val是:+ val);
这里我得到当前设置的val ...
但是当我尝试在写模式下打开...
registryKey = registryKey.OpenSubKey(@SYSTEM\CurrentControlSet \ Services \ USBSTOR,true);
并尝试设置值为4到di sable它无法工作......
registryKey.SetValue(开始,4);
I need to disable USB port of the computer using c# ..
below is the solution which is working for 32 bit windows but not working 64 bit ... I need a same function which can do the same thing for 64 bit ....
//disable USB storage...
Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 4, Microsoft.Win32.RegistryValueKind.DWord);
//enable USB storage...
Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 3, Microsoft.Win32.RegistryValueKind.DWord);
i can read the value on windows 64 bit but can not write the value....
RegistryKey registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
Console.WriteLine("registryKey" + registryKey);
registryKey = registryKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR");
Object val = registryKey.GetValue("Start");
Console.WriteLine("The val is:" + val);
here i am getting the current val which is set ...
but when i try to open in write mode...
registryKey = registryKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true);
and try to set a value 4 to disable it cant work...
registryKey.SetValue("Start", 4);
下载此工具:
http://support.microsoft.com/kb/311272 [ ^ ]
你应该能够确定处理
相关代码,以便从该文章中做你想做的事。
Download this tool:
http://support.microsoft.com/kb/311272[^]
You should be able to determineProcess
-related code to do what you want to do from that article.
试试这个:
http://www.programmersheaven.com/mb/dotnet/337951/337951/programatically-enable--disable-usb-port-using-cnet/ [ ^ ]
希望它有所帮助:)
Try this:
http://www.programmersheaven.com/mb/dotnet/337951/337951/programatically-enable--disable-usb-port-using-cnet/[^]
hope it helps :)
这篇关于以编程方式禁用USB设备。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文