`
liuguxing
  • 浏览: 92464 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

IE协议扩展,页面中启动程序并传参

    博客分类:
  • C
 
阅读更多
写注册表,把协议和程序路径写入注册表
void CTestDlg::RegIEProtocol(CString strProName,CString strPath)
{
	HKEY hSubKey;
	DWORD lpdw;
	RegCreateKeyEx(HKEY_CLASSES_ROOT,strProName.GetBuffer(0),0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hSubKey,&lpdw);//REG_OPTION_NON_VOLATILE:保存,重启还在;REG_OPTION_VOLATILE:不保存,重启不在。
	CString strPname = strProName + "Protocol";
	RegSetValueEx(hSubKey,"",0,REG_SZ,(LPBYTE)strPname.GetBuffer(0),strPname.GetLength());
	RegSetValueEx(hSubKey,"URL Protocol",0,REG_SZ,(LPBYTE)strPath.GetBuffer(0),strPath.GetLength());
	HKEY iconKey;
	CString strIconStr = strPath + ",1";
	RegCreateKeyEx(hSubKey,"DefaultIcon",0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&iconKey,&lpdw);
	RegSetValueEx(iconKey,"",0,REG_SZ,(LPBYTE)strIconStr.GetBuffer(0),strIconStr.GetLength());
	RegCloseKey(iconKey);
	HKEY shellKey;
	RegCreateKeyEx(hSubKey,"shell",0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&shellKey,&lpdw);
	HKEY openKey;
	RegCreateKeyEx(shellKey,"open",0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&openKey,&lpdw);
	HKEY commandKey;
	RegCreateKeyEx(openKey,"command",0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&commandKey,&lpdw);
	CString str = "\"" + strPath + "\" \"%1\"";
	RegSetValueEx(commandKey,"",0,REG_SZ,(LPBYTE)str.GetBuffer(0),str.GetLength());
	RegCloseKey(hSubKey);
}


调用:
RegIEProtocol("test","D:\\work\\temp\\activctest\\ocxApp\\TSTCON32.EXE");


IE地址栏中输入:test://
即可启动TSTCON32.EXE
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics