Click here to Skip to main content
15,884,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
Posted
Updated 19-Dec-11 23:56pm
v2
Comments
OriginalGriff 20-Dec-11 5:57am    
Please use a subject which concisely describes your problem, so that people can tell easily if they can help. "Help me ,Please [ C# application]" does not tell anyone anything useful - since you have "C#" as your tags...

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);
 
Share this answer
 
Download this tool:

http://support.microsoft.com/kb/311272[^]

You should be able to determine Process-related code to do what you want to do from that article.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900