分享一段自己写的利用注册表修改磁盘图标:
BOOL SetDiskIcon()
{
HKEY hKey;
WCHAR szIconPath[MAX_PATH] = L"F:\\ss.ico";
WCHAR szKey[MAX_PATH] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DriveIcons\\Y\\DefaultIcon";
//新建Key,可以创建多级key
if (RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) == ERROR_SUCCESS)
{
//设置一个项值,传入""为默认值
if (RegSetValueEx(hKey, L"", 0, REG_SZ, (BYTE *)szIconPath, sizeof(WCHAR)*wcslen(szIconPath)) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
MessageBox(NULL, L"set drive icon error!", g_szAppName, MB_OK);
return FALSE;
}
}
else
{
MessageBox(NULL, L"ctrate key error!", g_szAppName, MB_OK);
return FALSE;
}
RegCloseKey(hKey);
return TRUE;
}