简体   繁体   中英

Disable USB port from access smart-phone memory (without Group policy) in C#

Hi I am currently working on an application to Disable/Enable USB port programmatically in C#

I have found the following code snippet to Enable/disable the USB port. It's working fine with normal USB Sticks. But unfortunately its not disabling the Smartphone's memory card access.

//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 have googled for a better solution to solve this issue. I found some suggestions to use group policy for achieve the same. But my application is not intent to use the group policies. SO is there any solution is available like edit any registry key to achieve the Smart phone's memory access restriction programmaticaly in c# ?

I could able to solve this issue by registry value change. The details are as follows,

For Disable USB port from access Smart-phone memory as well as Memory Sticks:

created the DWORD parameter Deny_All with the value 00000001 in the registry key HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\RemovableStorageDevices .

For Allow Access:

created the DWORD parameter Deny_All with the value 00000000 in the registry key HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\RemovableStorageDevices .

Note:- To effect the access permission change , we have to restart the PC

The C# Code Snippet is as follows,

For Allow Access:

Registry.SetValue(@"HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\RemovableStorageDevices", "Deny_All", 0, RegistryValueKind.DWord);

For Restrict the Access:

Registry.SetValue(@"HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\RemovableStorageDevices", "Deny_All", 1, RegistryValueKind.DWord);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM