Questa è una continuazione della mia domanda here. Sto creando un elenco aperto con il tipo * .bmp.As per le risposte per quella domanda, ho creato un elenco delle applicazioni in aperto con l'elenco delle chiavi del Registro di sistema.Come ottenere la visualizzazione del nome dell'applicazione nell'elenco aperto?
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);
}
}
}
}
}
Questo metodo restituirà un elenco di nomi di applicazioni come,
- Paint.Picture
- ehshell.exe
- MSPaint.exe
- ois.exe
- VisualStudio. bmp.10.0
- QuickTime.bmp
Questi sono PrgIds e posso ottenere il comando che deve essere eseguito per aprire l'applicazione specifica da
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;
}
ora Come faccio ad avere il nome dell'applicazione che deve essere visualizzato nel menu? Ogni volta che si inizia a utilizzare una nuova applicazione, il sistema operativo Windows estrae automaticamente il nome dell'applicazione dalla risorsa di versione del file exe e lo memorizza per utilizzarlo in un secondo momento, nella chiave di registro nota come "MuiCache". I dati di MUICache sono archiviati in HKEY_CURRENT_USER \ Software \ Classes \ Local Settings \ Software \ Microsoft \ Windows \ Shell \ MuiCache
ma non possiamo garantire che l'applicazione sia stata eseguita almeno una volta. Inoltre possiamo ottenere direttamente la chiave di decriptazione da le risorse versione del file ma ho qualche difficoltà a dividere il percorso dell'applicazione da comandi come
% SystemRoot% \ System32 \ rundll32.exe "% Programmi% \ Windows Photo Viewer \ PhotoViewer.dll", ImageView_Fullscreen% 1
Come posso ottenere le informazioni sul nome?
Di seguito l'elenco dei miei comandi
- "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: \ Programmi (x86) \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ devenv.exe \ "/ dde"
- "C: \ Programmi (x86) \ QuickTime \ PictureViewer.exe \ "% 1 \""
sì amico .. .but Non riesco a trovare un metodo per dividere in modo coerente il percorso exe o dll dal comando, ad esempio: nel caso di "% SystemRoot% \ System32 \ rundll32.exe"% ProgramFiles% \ Windows Photo Viewer \ PhotoViewer. dll ", ImageView_Fullscreen% 1", ho bisogno di dividere PhotoViewer.dll così tha t per ottenere la descrizione da FileVersionInfo in altri casi come "C: \\ Windows \\ system32 \\ NOTEPAD.EXE% 1" questo è semplice – biju