取文件后缀
1 2 |
LPWSTR lpszExt = PathFindExtension(lpszFile); CString strExt = lpszExt; |
Ext默认打开应用
- 仅处理了
HKEY_CLASSES_ROOT
这一层。 HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mp4\UserChoice
这里的优先级会更高。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
BOOL KRcmdMonDefendImpl::GetExistDefaultApplication(LPCTSTR lpszExt, BOOL& bDefaultApplication, CString& strApplicationName) { BOOL bRet = FALSE; bDefaultApplication = FALSE; strApplicationName.Empty(); do { if (lpszExt == NULL) { break; } cf::reg::KRegister reg; if (!reg.Open(HKEY_CLASSES_ROOT, lpszExt)) { break; } CString strRes; if (!reg.Read(L"", strRes)) { break; } bDefaultApplication = !strRes.IsEmpty(); if (!bDefaultApplication) { break; } CString strTempPath; strTempPath.Format(L"%s\\shell\\open\\command", strRes); if (!reg.Open(HKEY_CLASSES_ROOT, strTempPath)) { break; } CString strTempRes; if (!reg.Read(L"", strTempRes)) { break; } if (strTempRes.IsEmpty()) { break; } CString strExpanded = ExpandEnvironmentStrings(strTempRes); std::wstring strTempResult(strExpanded); std::wstring strExt(L".exe"); std::wstring strExeName; if (!GetFileNameFromCmdLine(strTempResult, strExt, TRUE, strExeName)) { break; } strApplicationName = strExeName.c_str(); bRet = TRUE; } while (false); return bRet; } |
对路径中的环境变量展开
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
CString KRcmdMonDefendImpl::ExpandEnvironmentStrings(const TCHAR *szSrc) { CString strRes(szSrc); HANDLE hProcess; HANDLE hToken; hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()); bool bRet = false; if (hProcess != nullptr) { bRet = OpenProcessToken(hProcess, TOKEN_IMPERSONATE | TOKEN_QUERY, &hToken); if (bRet) { TCHAR szExpandedPath[MAX_PATH]; bRet = ExpandEnvironmentStringsForUser(hToken, szSrc, szExpandedPath, sizeof(szExpandedPath)); if (bRet) { strRes = szExpandedPath; } CloseHandle(hToken); } CloseHandle(hProcess); } return strRes; } |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ Soui一03/17
- ♥ Soui六06/01
- ♥ Windows 核心编程 _ 线程内幕07/06
- ♥ Windows 核心编程 _ 用户模式:线程同步二07/16
- ♥ 各平台调试方法总结记述一09/25
- ♥ Windows 核心编程 _ 内核对象:线程同步三07/31