掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
アプリ起動 (ID:69374)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
ShellExecuteでもパスが通ってないと開けないでしょう。 拡張子に関連づいているファイルであればShellExecuteで開けるでしょうけど。 (ShellExcute(NULL, "open", "XXX.xls" ・・・みたいに) 1の方法を http://dobon.net/vb/dotnet/system/findassociatedexe.html より記述してみました。 bool GetShellAppPath(System::String^% path, System::String^ ext) { bool bResult = false; if ((ext != nullptr) && (ext->Length > 0)) { if (ext[0] != L'.') { ext = ext->Insert(0, L"."); } Microsoft::Win32::RegistryKey^ regKey = Microsoft::Win32::Registry::ClassesRoot->OpenSubKey(ext); if (regKey != nullptr) { System::String^ fileType = static_cast<System::String^>(regKey->GetValue(L"")); regKey->Close(); regKey = Microsoft::Win32::Registry::ClassesRoot->OpenSubKey(System::String::Format(L"{0}\\\\shell\\\\open\\\\command", fileType)); if (regKey != nullptr) { System::String^ command = static_cast<System::String^>(regKey->GetValue(L"")); regKey->Close(); command = command->Trim(); int index; // "xxxx\xx xxx\xxx.exe" %1 形式の場合 if (command->IndexOf(L'"') == 0) { index = command->IndexOf(L'"', 1); if (index > 0) { path = command->Substring(1, index - 1); bResult = true; } } // xxxx\xxxxx\xxx.exe %1 形式の場合 else { index = command->IndexOf(L' ', 0); if (index > 0) { path = command->Substring(0, index); } else { path = command; } bResult = true; } } } } return bResult; } 使用例 String^ path; if (GetShellAppPath(path, L"xls")) { MessageBox::Show(path); }
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.