2012-08-16 6 views
5

यह मेरे प्रश्न here की निरंतरता है। मैं उस प्रश्न के उत्तर के अनुसार * .bmp.As प्रकार के लिए सूची के साथ एक खुला बना रहा हूं, मैंने रजिस्ट्री कुंजियों की सूची के साथ खुले में एप्लिकेशन की एक सूची बनाई है।ओपन-इन सूची में एप्लिकेशन का नाम कैसे प्रदर्शित किया जाए?

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); 
        } 
       } 
      } 
     } 

    } 

इस विधि की तरह आवेदन नामों की एक सूची वापस आ जाएगी,

  • Paint.Picture
  • ehshell.exe
  • MSPaint.exe
  • ois.exe
  • VisualStudio। bmp.10.0
  • QuickTime.bmp

ये PrgIds हैं और मैं आदेश

 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; 
    } 

से विशिष्ट अनुप्रयोग को खोलने के लिए निष्पादित करने की आवश्यकता है कि अब मैं आवेदन नाम है जो मेनू में प्रदर्शित करने के लिए कैसे मिलता है मिल सकता है? प्रत्येक बार जब आप एक नए एप्लिकेशन का उपयोग शुरू करते हैं, तो विंडोज ऑपरेटिंग सिस्टम स्वचालित रूप से एक्सई फ़ाइल के संस्करण संसाधन से एप्लिकेशन नाम निकालता है, और इसे बाद में उपयोग करने के लिए संग्रहीत करता है, रजिस्ट्री कुंजी में 'मुई कैश' के नाम से जाना जाता है। MUICache डेटा HKEY_CURRENT_USER \ Software \ Classes \ Local Settings \ Software \ Microsoft \ Windows \ Shell \ MuiCache

के तहत संग्रहीत किया जाता है लेकिन हम गारंटी नहीं देते कि एप्लिकेशन कम से कम एक बार चलाया गया है। साथ ही हम सीधे से विलम्ब की कुंजी प्राप्त कर सकते हैं फ़ाइल का संस्करण संसाधनों, लेकिन मैं बाहर बंटवारे

% SystemRoot तरह% \ System32 \ rundll32.exe "% ProgramFiles% \ windows फोटो व्यूअर \ PhotoViewer.dll" आदेशों से आवेदन रास्ते में कुछ परेशानी है, ImageView_Fullscreen% 1

मुझे कैसे मिल सकता है नाम की जानकारी?

मेरे आदेशों की सूची के नीचे

  • "C: \ Windows \ System32 \ rundll32.exe \" C: \ Program Files \ विंडोज फ़ोटो दर्शक \ PhotoViewer.dll \ ", ImageView_Fullscreen% 1"
  • "\" C: \ Windows \ ehome \ ehshell.exe \ "\"% 1 \ ""
  • "C: \ कार्यक्रम ~ 1 \ MIF5BA ~ 1 \ Office14 \ OIS.EXE/shellOpen \"% 1 \ ""
  • "\" सी: \ प्रोग्राम फ़ाइलें (x86) \ माइक्रोसॉफ्ट विजुअल स्टूडियो 10.0 \ Common7 \ IDE \ devenv.exe \ "/ dde"
  • "सी: \ प्रोग्राम फ़ाइलें (x86) \ क्विकटाइम \ पिक्चर व्यूअर।exe \ "% 1 \" "

उत्तर

2

आप कमांड की सूची जानते हैं, तो आप वर्णन

FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe")); 
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe"); 


    // Print the file name and version number. 
    Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' + 
     "Version number: " + myFileVersionInfo.FileVersion); 
+0

हाँ साथी में मदद करता है .. लेकिन मैं आदेश से exe या dll पथ को लगातार विभाजित करने के लिए कोई विधि नहीं ढूंढ पा रहा हूं उदाहरण: "% SystemRoot% \ System32 \ rundll32.exe"% ProgramFiles% \ Windows Photo Viewer \ PhotoViewer के मामले में। डीएलएल ", ImageView_Fullscreen% 1", मुझे PhotoViewer.dll को विभाजित करने की आवश्यकता है अन्य मामलों में FileVersionInfo से विवरण प्राप्त करने के लिए जैसे "सी: \\ विंडोज़ \\ system32 \\ NotePAD.EXE% 1" यह सीधे आगे है – biju

2

बिल्डिंग अमल के समाधान के लिए, आप केवल है दो स्थितियों नीचे दिए गए कोड का उपयोग कर प्राप्त कर सकते हैं आप को संभाल करने की जरूरत है:

1) उन है कि शुरू "C: \ Windows \ System32 \ rundll32.exe" 2) सब कुछ

आप किसी न किसी तरह कुछ आप स्थानापन्न सकता है "चाहते हैं C: \ Windows \ System32 \ rundll32.ex ई "एक खाली स्ट्रिंग होगा। खाली तारों के साथ बदलें, अपनी स्ट्रिंग को पहले फॉरवर्ड स्लैश (/) या% को समाप्त करें और फिर परिणाम को ट्रिम करें।

आपको .dll या .exe के नाम से छोड़ा जाएगा, जिसके लिए आप नाम चाहते हैं (यह संभवतः एक रेगेक्स के साथ थोड़ा और अधिक आकर्षक ढंग से किया जा सकता है और यदि आपको अधिक परिदृश्यों को संभालने की आवश्यकता है तो यह समाधान जटिल हो जाएगा)

फिर आप अमल से कोड के बिट के माध्यम से इसे चलाते हैं और आपके पास होना चाहिए आप क्या चाहते हैं

2

अद्यतन:। माफ करना, मैं अपनी पोस्ट पढ़ने में भूलना

यह मदद करता है केवल यदि आप डिफ़ॉल्ट अनुप्रयोग के लिए देखो। विस्तार के आधार पर नाम। प्रोजेड पर आधारित नहीं है।

public static class FileAssoc 
{ 
    [DllImport("Shlwapi.dll", CharSet = CharSet.Auto, SetLastError = true)] 
    static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder sOut, [In][Out] ref uint nOut); 

    [Flags] 
    public enum AssocF 
    { 
     Init_NoRemapCLSID = 0x1, 
     Init_ByExeName = 0x2, 
     Open_ByExeName = 0x2, 
     Init_DefaultToStar = 0x4, 
     Init_DefaultToFolder = 0x8, 
     NoUserSettings = 0x10, 
     NoTruncate = 0x20, 
     Verify = 0x40, 
     RemapRunDll = 0x80, 
     NoFixUps = 0x100, 
     IgnoreBaseClass = 0x200 
    } 

    public enum AssocStr 
    { 
     Command = 1, 
     Executable, 
     FriendlyDocName, 
     FriendlyAppName, 
     NoOpen, 
     ShellNewValue, 
     DDECommand, 
     DDEIfExec, 
     DDEApplication, 
     DDETopic 
    } 

    public static string GetApplicationName(string fileExtensionIncludingDot) 
    { 
     uint cOut = 0; 
     if (AssocQueryString(AssocF.Verify, AssocStr.FriendlyAppName, fileExtensionIncludingDot, null, null, ref cOut) != 1) 
      return null; 
     StringBuilder pOut = new StringBuilder((int)cOut); 
     if (AssocQueryString(AssocF.Verify, AssocStr.FriendlyAppName, fileExtensionIncludingDot, null, pOut, ref cOut) != 0) 
      return null; 
     return pOut.ToString(); 
    } 
} 

आप इस

string applicationName = FileAssoc.GetApplicationName(".docx"); 
// results in "Microsoft Office Word" 
0

मेरे कोड शामिल है कि कुछ आम त्रुटियों से रोकने के लिए जाँच की तरह उपयोग कर सकते हैं ... उम्मीद है कि यह :-)

using System; 
using System.Diagnostics; 
using System.IO; 
using System.Runtime.InteropServices; 
using System.Text; 

namespace HQ.Util.Unmanaged 
{ 
    /// <summary> 
    /// Usage: string executablePath = FileAssociation.GetExecFileAssociatedToExtension(pathExtension, "open"); 
    /// Usage: string command FileAssociation.GetExecCommandAssociatedToExtension(pathExtension, "open"); 
    /// </summary> 
    public static class FileAssociation 
    { 
     /// <summary> 
     /// 
     /// </summary> 
     /// <param name="ext"></param> 
     /// <param name="verb"></param> 
     /// <returns>Return null if not found</returns> 
     public static string GetExecCommandAssociatedToExtension(string ext, string verb = null) 
     { 
      if (ext[0] != '.') 
      { 
       ext = "." + ext; 
      } 

      string executablePath = FileExtentionInfo(AssocStr.Command, ext, verb); 

      // Ensure to not return the default OpenWith.exe associated executable in Windows 8 or higher 
      if (!string.IsNullOrEmpty(executablePath) && File.Exists(executablePath) && 
       !executablePath.ToLower().EndsWith(".dll")) 
      { 
       if (executablePath.ToLower().EndsWith("openwith.exe")) 
       { 
        return null; // 'OpenWith.exe' is th windows 8 or higher default for unknown extensions. I don't want to have it as associted file 
       } 
       return executablePath; 
      } 
      return executablePath; 
     } 

     /// <summary> 
     /// 
     /// </summary> 
     /// <param name="ext"></param> 
     /// <param name="verb"></param> 
     /// <returns>Return null if not found</returns> 
     public static string GetExecFileAssociatedToExtension(string ext, string verb = null) 
     { 
      if (ext[0] != '.') 
      { 
       ext = "." + ext; 
      } 

      string executablePath = FileExtentionInfo(AssocStr.Executable, ext, verb); // Will only work for 'open' verb 
      if (string.IsNullOrEmpty(executablePath)) 
      { 
       executablePath = FileExtentionInfo(AssocStr.Command, ext, verb); // required to find command of any other verb than 'open' 

       // Extract only the path 
       if (!string.IsNullOrEmpty(executablePath) && executablePath.Length > 1) 
       { 
        if (executablePath[0] == '"') 
        { 
         executablePath = executablePath.Split('\"')[1]; 
        } 
        else if (executablePath[0] == '\'') 
        { 
         executablePath = executablePath.Split('\'')[1]; 
        } 
       } 
      } 

      // Ensure to not return the default OpenWith.exe associated executable in Windows 8 or higher 
      if (!string.IsNullOrEmpty(executablePath) && File.Exists(executablePath) && 
       !executablePath.ToLower().EndsWith(".dll")) 
      { 
       if (executablePath.ToLower().EndsWith("openwith.exe")) 
       { 
        return null; // 'OpenWith.exe' is th windows 8 or higher default for unknown extensions. I don't want to have it as associted file 
       } 
       return executablePath; 
      } 
      return executablePath; 
     } 

     [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)] 
     static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder pszOut, [In][Out] ref uint pcchOut); 

     private static string FileExtentionInfo(AssocStr assocStr, string doctype, string verb) 
     { 
      uint pcchOut = 0; 
      AssocQueryString(AssocF.Verify, assocStr, doctype, verb, null, ref pcchOut); 

      Debug.Assert(pcchOut != 0); 
      if (pcchOut == 0) 
      { 
       return ""; 
      } 

      StringBuilder pszOut = new StringBuilder((int)pcchOut); 
      AssocQueryString(AssocF.Verify, assocStr, doctype, verb, pszOut, ref pcchOut); 
      return pszOut.ToString(); 
     } 

     [Flags] 
     public enum AssocF 
     { 
      Init_NoRemapCLSID = 0x1, 
      Init_ByExeName = 0x2, 
      Open_ByExeName = 0x2, 
      Init_DefaultToStar = 0x4, 
      Init_DefaultToFolder = 0x8, 
      NoUserSettings = 0x10, 
      NoTruncate = 0x20, 
      Verify = 0x40, 
      RemapRunDll = 0x80, 
      NoFixUps = 0x100, 
      IgnoreBaseClass = 0x200 
     } 

     public enum AssocStr 
     { 
      Command = 1, 
      Executable, 
      FriendlyDocName, 
      FriendlyAppName, 
      NoOpen, 
      ShellNewValue, 
      DDECommand, 
      DDEIfExec, 
      DDEApplication, 
      DDETopic 
     } 



    } 
} 
संबंधित मुद्दे

 संबंधित मुद्दे