BOOL WriteURISchemaReg() {
CString strExePath = m_strInstallPath + _T("xyzlink.exe");
CString strProtocolName = _T("XyzlinkProtocol");
HKEY hRootKey = NULL;
DWORD dwKeyValue = 0;
DWORD dwDisposition = 0;
UCHAR szBuf[MAX_PATH] = { 0 };
long lRet = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, ProtocalNodeName, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hRootKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) {
return FALSE;
}
lRet = ::RegSetValueEx(hRootKey, NULL, 0, REG_SZ, (LPBYTE)(LPCTSTR)strProtocolName, strProtocolName.GetLength() * sizeof(TCHAR));
if (lRet != ERROR_SUCCESS) {
RegCloseKey(hRootKey);
return FALSE;
}
CString strKey = _T("URL Protocol");
lRet = RegSetValueEx(hRootKey, strKey.GetBuffer(0), 0, REG_SZ, (LPBYTE)(LPCTSTR)strExePath, strExePath.GetLength() * sizeof(TCHAR));
if (lRet != ERROR_SUCCESS) {
RegCloseKey(hRootKey);
return FALSE;
}
strKey = _T("DefaultIcon");
HKEY hDefaultIconKey = NULL;
lRet = RegCreateKeyEx(hRootKey, strKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hDefaultIconKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) {
RegCloseKey(hRootKey);
return FALSE;
}
CString strExePathPlus = strExePath + _T(",1");
lRet = RegSetValueEx(hDefaultIconKey, NULL, 0, REG_SZ, (LPBYTE)(LPCTSTR)strExePathPlus, strExePathPlus.GetLength() * sizeof(TCHAR));
if (lRet != ERROR_SUCCESS) {
RegCloseKey(hDefaultIconKey);
RegCloseKey(hRootKey);
return FALSE;
}
strKey = _T("shell");
HKEY hShellKey = NULL;
lRet = RegCreateKeyEx(hDefaultIconKey, strKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hShellKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) {
RegCloseKey(hDefaultIconKey);
RegCloseKey(hRootKey);
return FALSE;
}
strKey = _T("open");
HKEY hOpenKey = NULL;
lRet = RegCreateKeyEx(hShellKey, strKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hOpenKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) {
RegCloseKey(hDefaultIconKey);
RegCloseKey(hRootKey);
return FALSE;
}
strKey = _T("command");
HKEY hCommandKey = NULL;
lRet = RegCreateKeyEx(hOpenKey, strKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hCommandKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) {
RegCloseKey(hOpenKey);
RegCloseKey(hDefaultIconKey);
RegCloseKey(hRootKey);
return FALSE;
}
CString strCmdParam;
strCmdParam.Format(_T("\"%s\" \"%%1\""), strExePath);
lRet = RegSetValueEx(hCommandKey, NULL, 0, REG_SZ, (LPBYTE)(LPCTSTR)strCmdParam, strCmdParam.GetLength() * sizeof(TCHAR));
if (lRet != ERROR_SUCCESS) {
RegCloseKey(hCommandKey);
RegCloseKey(hOpenKey);
RegCloseKey(hDefaultIconKey);
RegCloseKey(hRootKey);
return FALSE;
}
RegCloseKey(hCommandKey);
RegCloseKey(hOpenKey);
RegCloseKey(hDefaultIconKey);
RegCloseKey(hRootKey);
return TRUE;
}