默认浏览器是IE,我设置成火狐,代码如下:(为了简化用的绝对路径)
HKEY key;
RegOpenKey(HKEY_CLASSES_ROOT,_T("Http\\shell\\open\\command"),&key);
DWORD ret1=GetLastError();
TCHAR val[]=_T("\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" -requestPending -osint -url \"%1\"");
RegSetValueEx(key,NULL,0,REG_EXPAND_SZ,(LPBYTE)val,sizeof(val));
DWORD ret=GetLastError();
RegCloseKey(key);
RegOpenKey(HKEY_CLASSES_ROOT,_T("Http\\DefaultIcon"),&key);
TCHAR val1_http[]=_T("C:\\Program Files\\Mozilla Firefox\\firefox.exe,1");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val1_http,sizeof(val1_http));
RegCloseKey(key);
RegOpenKey(HKEY_CLASSES_ROOT,_T("https\\shell\\open\\command"),&key);
TCHAR val_https[]=_T("\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" -requestPending -osint -url \"%1\"");
RegSetValueEx(key,NULL,0,REG_EXPAND_SZ,(LPBYTE)val_https,sizeof(val_https));
RegCloseKey(key);
RegOpenKey(HKEY_CLASSES_ROOT,_T("https\\DefaultIcon"),&key);
TCHAR val1_https[]=_T("C:\\Program Files\\Mozilla Firefox\\firefox.exe,1");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val1_https,sizeof(val1_https));
RegCloseKey(key);
RegOpenKey(HKEY_CLASSES_ROOT,_T("ftp\\shell\\open\\command"),&key);
TCHAR val_1[]=_T("\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" -requestPending -osint -url \"%1\"");
RegSetValueEx(key,NULL,0,REG_EXPAND_SZ,(LPBYTE)val_1,sizeof(val_1));
RegCloseKey(key);
RegOpenKey(HKEY_CLASSES_ROOT,_T("ftp\\DefaultIcon"),&key);
TCHAR val1[]=_T("C:\\Program Files\\Mozilla Firefox\\firefox.exe,1");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val1,sizeof(val1));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\.htm"),&key);
TCHAR val2[]=_T("FirefoxHTML");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val2,sizeof(val2));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\.html"),&key);
TCHAR val2_html[]=_T("FirefoxHTML");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val2_html,sizeof(val2_html));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\.shtml"),&key);
TCHAR val2_shtml[]=_T("FirefoxHTML");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val2_shtml,sizeof(val2_shtml));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\.xht"),&key);
TCHAR val2_xht[]=_T("FirefoxHTML");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val2_xht,sizeof(val2_xht));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\.xhtml"),&key);
TCHAR val2_xhtml[]=_T("FirefoxHTML");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val2_xhtml,sizeof(val2_xhtml));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\ftp\\DefaultIcon"),&key);
TCHAR val2_ftp[]=_T("C:\\Program Files\\Mozilla Firefox\\firefox.exe,1");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val2_ftp,sizeof(val2_ftp));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\http\\DefaultIcon"),&key);
TCHAR val2_http[]=_T("C:\\Program Files\\Mozilla Firefox\\firefox.exe,1");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val2_http,sizeof(val2_http));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\https\\DefaultIcon"),&key);
TCHAR val2_https[]=_T("C:\\Program Files\\Mozilla Firefox\\firefox.exe,1");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val2_https,sizeof(val2_https));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\https\\shell\\open\\command"),&key);
TCHAR val2_https_1[]=_T("\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" -requestPending -osint -url \"%1\"");
RegSetValueEx(key,NULL,0,REG_EXPAND_SZ,(LPBYTE)val2_https_1,sizeof(val2_https_1));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\http\\shell\\open\\command"),&key);
TCHAR val2_http_1[]=_T("\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" -requestPending -osint -url \"%1\"");
RegSetValueEx(key,NULL,0,REG_EXPAND_SZ,(LPBYTE)val2_http_1,sizeof(val2_http_1));
RegCloseKey(key);
RegOpenKey(HKEY_CURRENT_USER,_T("Software\\Classes\\ftp\\shell\\open\\command"),&key);
TCHAR val2_ftp_1[]=_T("\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" -requestPending -osint -url \"%1\"");
RegSetValueEx(key,NULL,0,REG_EXPAND_SZ,(LPBYTE)val2_ftp_1,sizeof(val2_ftp_1));
RegCloseKey(key);
//RegOpenKey(HKEY_CLASSES_ROOT,_T("HKEY_CLASSES_ROOT\\InternetShortcut\\shell\\open\\command"),&key);
RegOpenKey(HKEY_CLASSES_ROOT,_T(".html"),&key);
TCHAR val4[]=_T("FirefoxHTML");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val4,sizeof(val4));
RegCloseKey(key);
RegOpenKey(HKEY_CLASSES_ROOT,_T(".htm"),&key);
TCHAR val5[]=_T("FirefoxHTML");
RegSetValueEx(key,NULL,0,REG_SZ,(LPBYTE)val5,sizeof(val5));
RegCloseKey(key);
//刷新操作
::SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,SPI_SETNONCLIENTMETRICS,0);
顺便说个小问题,用RegSetValue修改注册表内容不成功,改成RegSetValueEx修改OK,系统是xp sp3。代码运行后在QQ聊天窗口中打开www.xxx.com是用火狐了,打开xxx.html仍旧是IE打开的,另外在桌面右键刷新后xx.html文件的图标关联也是正确的(这步能在代码中实现吗?用代码替换掉F5的刷新操作?)
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)