Đây là phần tiếp theo của câu hỏi của tôi here. Tôi đang tạo một danh sách mở với kiểu * .bmp.As cho mỗi câu trả lời cho câu hỏi đó, tôi đã tạo một danh sách các ứng dụng trong danh sách mở từ các khóa registry.Cách nhận tên Ứng dụng được hiển thị trong danh sách mở với danh sách?
public void RecommendedPrograms(string ext)
{
string baseKey = @"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\." + ext;
using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(baseKey + @"\OpenWithList"))
{
if (rk != null)
{
string mruList = (string)rk.GetValue("MRUList");
if (mruList != null)
{
foreach (char c in mruList.ToString())
{
string str=rk.GetValue(c.ToString()).ToString();
if (!progs.Contains(str))
{
progs.Add(str);
}
}
}
}
}
using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(baseKey + @"\OpenWithProgids"))
{
if (rk != null)
{
foreach (string item in rk.GetValueNames())
progs.Add(item);
}
}
using (RegistryKey rk = Registry.ClassesRoot.OpenSubKey("." + ext + @"\OpenWithList"))
{
if (rk != null)
{
foreach (var item in rk.GetSubKeyNames())
{
if (!progs.Contains(item))
{
progs.Add(item.ToString());
}
}
}
}
using (RegistryKey rk = Registry.ClassesRoot.OpenSubKey("." + ext + @"\OpenWithProgids"))
{
if (rk != null)
{
foreach (string item in rk.GetValueNames())
{
if (!progs.Contains(item))
{
progs.Add(item);
}
}
}
}
}
Phương pháp này sẽ trả về một danh sách tên ứng dụng như thế nào,
- Paint.Picture
- ehshell.exe
- MSPaint.exe
- ois.exe
- VisualStudio. bmp.10.0
- QuickTime.bmp
Đây là những PrgIds và tôi có thể nhận lệnh mà cần phải được thực hiện để mở ứng dụng cụ thể từ các
public string GetRegisteredApplication(string StrProgID)
{
//
// Return registered application by file's extension
//
RegistryKey oHKCR;
RegistryKey oOpenCmd;
string command;
if (Environment.Is64BitOperatingSystem == true)
{
oHKCR = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, RegistryView.Registry64);
}
else
{
oHKCR = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, RegistryView.Registry32);
}
try
{
oOpenCmd = oHKCR.OpenSubKey(StrProgID + "\\shell\\open\\command");
if (oOpenCmd == null)
{
oOpenCmd = oHKCR.OpenSubKey("\\Applications\\" + StrProgID + "\\shell\\open\\command");
}
if (oOpenCmd != null)
{
command = oOpenCmd.GetValue(null).ToString();
oOpenCmd.Close();
}
else
{
return null;
}
}
catch (Exception ex)
{
return null;
}
return command;
}
Bây giờ Làm thế nào để có được tên ứng dụng mà đã được hiển thị trong trình đơn? Mỗi lần bạn bắt đầu sử dụng ứng dụng mới, hệ điều hành Windows sẽ tự động trích xuất tên ứng dụng từ tài nguyên phiên bản của tệp exe và lưu trữ nó để sử dụng sau này, trong khóa Registry được gọi là 'MuiCache'. Dữ liệu MUICache được lưu trữ trong HKEY_CURRENT_USER \ Software \ Classes \ Local \ Software \ Microsoft \ Windows \ Shell \ MuiCache
nhưng chúng tôi không thể bảo đảm rằng ứng dụng đã được chạy ít nhất một lần. Ngoài ra, chúng tôi có thể trực tiếp nhận mã giảm giá từ các nguồn lực phiên bản của tập tin, nhưng tôi có một số rắc rối về chia nhỏ ra đường dẫn ứng dụng từ các lệnh như
% SystemRoot% \ System32 \ rundll32.exe "% ProgramFiles% \ Windows Photo Viewer \ PhotoViewer.dll", ImageView_Fullscreen% 1
Làm cách nào tôi có thể nhận được thông tin về tên?
Bên dưới danh sách các lệnh của tôi
- "C: \ Windows \ System32 \ rundll32.exe \" C: \ Program Files \ Windows Photo Viewer \ PhotoViewer.dll \", ImageView_Fullscreen% 1"
- "\" C: \ Windows \ eHome \ ehshell.exe \ "\"% 1 \ ""
- "C: \ PROGRA ~ 1 \ MIF5BA ~ 1 \ Office14 \ OIS.EXE/shellOpen \"% 1 \ ""
- "\" C: \ Tệp chương trình (x86) \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ devenv.exe \ "/ dde"
- "C: \ Program Files (x86) \ QuickTime \ PictureViewer.exe \ "% 1 \""
có bạn thân .. Nhưng tôi không thể tìm thấy một phương pháp để phân chia một cách nhất quán đường dẫn exe hoặc dll từ lệnh, ví dụ: trong trường hợp "% SystemRoot% \ System32 \ rundll32.exe"% ProgramFiles% \ Windows Photo Viewer \ PhotoViewer. dll ", ImageView_Fullscreen% 1", tôi cần phải tách ra PhotoViewer.dll để tha t để có được mô tả từ FileVersionInfo trong các trường hợp khác như "C: \\ Windows \\ system32 \\ NOTEPAD.EXE% 1" điều này là thẳng về phía trước – biju