C++简单代码设置U盘的可写性
转自:http://blog.csdn.net/cackeme/article/details/7825782
如题,主要用于本机限制U盘访问,代码如下:
/* @prarm dwValue,0为可写,1为不可写 */ BOOL SetUsbWriteProtect(DWORD dwValue) { HKEY hKey;; DWORD dwRet = RegCreateKey(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\StorageDevicePolicies",&hKey); if (dwRet != ERROR_SUCCESS) return FALSE; DWORD dwSize = sizeof(dwValue); dwRet = RegSetValueEx(hKey,"WriteProtect",0,REG_DWORD,(BYTE*)&dwValue,dwSize); RegCloseKey(hKey); if (dwRet == ERROR_SUCCESS) return TRUE; return FALSE; }