<legend id='U9LHh'><style id='U9LHh'><dir id='U9LHh'><q id='U9LHh'></q></dir></style></legend>
    <tfoot id='U9LHh'></tfoot>

      <i id='U9LHh'><tr id='U9LHh'><dt id='U9LHh'><q id='U9LHh'><span id='U9LHh'><b id='U9LHh'><form id='U9LHh'><ins id='U9LHh'></ins><ul id='U9LHh'></ul><sub id='U9LHh'></sub></form><legend id='U9LHh'></legend><bdo id='U9LHh'><pre id='U9LHh'><center id='U9LHh'></center></pre></bdo></b><th id='U9LHh'></th></span></q></dt></tr></i><div id='U9LHh'><tfoot id='U9LHh'></tfoot><dl id='U9LHh'><fieldset id='U9LHh'></fieldset></dl></div>

    1. <small id='U9LHh'></small><noframes id='U9LHh'>

        <bdo id='U9LHh'></bdo><ul id='U9LHh'></ul>

      1. 使用 C# 将 *.lnk 文件固定到 Windows 7 任务栏

        Pin *.lnk file to Windows 7 Taskbar using C#(使用 C# 将 *.lnk 文件固定到 Windows 7 任务栏)
        <legend id='Q6qKk'><style id='Q6qKk'><dir id='Q6qKk'><q id='Q6qKk'></q></dir></style></legend>
      2. <i id='Q6qKk'><tr id='Q6qKk'><dt id='Q6qKk'><q id='Q6qKk'><span id='Q6qKk'><b id='Q6qKk'><form id='Q6qKk'><ins id='Q6qKk'></ins><ul id='Q6qKk'></ul><sub id='Q6qKk'></sub></form><legend id='Q6qKk'></legend><bdo id='Q6qKk'><pre id='Q6qKk'><center id='Q6qKk'></center></pre></bdo></b><th id='Q6qKk'></th></span></q></dt></tr></i><div id='Q6qKk'><tfoot id='Q6qKk'></tfoot><dl id='Q6qKk'><fieldset id='Q6qKk'></fieldset></dl></div>
      3. <tfoot id='Q6qKk'></tfoot>

              <tbody id='Q6qKk'></tbody>

                <bdo id='Q6qKk'></bdo><ul id='Q6qKk'></ul>

                  <small id='Q6qKk'></small><noframes id='Q6qKk'>

                  本文介绍了使用 C# 将 *.lnk 文件固定到 Windows 7 任务栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  即使在 Windows 7 中以编程方式固定图标似乎也是不允许的(就像这里所说的那样:http://msdn.microsoft.com/en-us/library/dd378460(v=VS.85).aspx),有一些方法可以做到这一点使用一些 VB 脚本.有人在 C# 中找到了这样的方法:

                  Even the programmatic pinning of icons in Windows 7 seems it's not permitted (like it says here: http://msdn.microsoft.com/en-us/library/dd378460(v=VS.85).aspx), there are some methods for doing this by using some VB scripts. Someone found a way of doing this in C# like this:

                  private static void PinUnpinTaskBar(string filePath, bool pin)
                  {
                       if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
                  
                       // create the shell application object
                       dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
                  
                       string path = Path.GetDirectoryName(filePath);
                       string fileName = Path.GetFileName(filePath);
                  
                       dynamic directory = shellApplication.NameSpace(path);
                       dynamic link = directory.ParseName(fileName);
                  
                       dynamic verbs = link.Verbs();
                       for (int i = 0; i < verbs.Count(); i++)
                          {
                              dynamic verb = verbs.Item(i);
                              string verbName = verb.Name.Replace(@"&", string.Empty).ToLower();
                  
                              if ((pin && verbName.Equals("pin to taskbar")) || (!pin && verbName.Equals("unpin from taskbar")))
                              {
                  
                                  verb.DoIt();
                              }
                          }
                  
                          shellApplication = null;
                  }
                  

                  可以看出,代码利用了 .NET Framework 4.0 的特性.我想问的问题是:这个函数可以转换成同样的东西,但只使用 3.5 框架吗?有什么想法吗?

                  As can be seen, the code makes use of .NET Framework 4.0 features. The question I want to ask is: can this function be transformed so it would make the same thing, but using just 3.5 Framework? Any ideas?

                  推荐答案

                  简单...

                      private static void PinUnpinTaskBar(string filePath, bool pin) {
                          if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
                  
                          // create the shell application object
                          Shell shellApplication = new ShellClass();
                  
                          string path = Path.GetDirectoryName(filePath);
                          string fileName = Path.GetFileName(filePath);
                  
                          Folder directory = shellApplication.NameSpace(path);
                          FolderItem link = directory.ParseName(fileName);
                  
                          FolderItemVerbs verbs = link.Verbs();
                          for (int i = 0; i < verbs.Count; i++) {
                              FolderItemVerb verb = verbs.Item(i);
                              string verbName = verb.Name.Replace(@"&", string.Empty).ToLower();
                  
                              if ((pin && verbName.Equals("pin to taskbar")) || (!pin && verbName.Equals("unpin from taskbar"))) {
                  
                                  verb.DoIt();
                              }
                          }
                  
                          shellApplication = null;
                      }
                  

                  请务必添加对Microsoft Shell 控件和自动化"的 COM 引用.

                  Be sure to add a COM reference to "Microsoft Shell Controls And Automation".

                  如果您想保留使用 Activator.CreateInstance 的现有方法,这样您就不必拥有额外的 COM 互操作 DLL,那么您将不得不使用反射.但这会使代码更难看.

                  If you want to keep the existing method of using Activator.CreateInstance so you don't have to have the extra COM interop DLL then you'll have to use reflection. But that would make the code a lot uglier.

                  这篇关于使用 C# 将 *.lnk 文件固定到 Windows 7 任务栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  set equality in linq(在 linq 中设置相等)
                  HashSet conversion to List(HashSet 转换为 List)
                  How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                  Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)

                  <small id='sX50N'></small><noframes id='sX50N'>

                1. <legend id='sX50N'><style id='sX50N'><dir id='sX50N'><q id='sX50N'></q></dir></style></legend>
                      <bdo id='sX50N'></bdo><ul id='sX50N'></ul>
                        <tbody id='sX50N'></tbody>

                    • <i id='sX50N'><tr id='sX50N'><dt id='sX50N'><q id='sX50N'><span id='sX50N'><b id='sX50N'><form id='sX50N'><ins id='sX50N'></ins><ul id='sX50N'></ul><sub id='sX50N'></sub></form><legend id='sX50N'></legend><bdo id='sX50N'><pre id='sX50N'><center id='sX50N'></center></pre></bdo></b><th id='sX50N'></th></span></q></dt></tr></i><div id='sX50N'><tfoot id='sX50N'></tfoot><dl id='sX50N'><fieldset id='sX50N'></fieldset></dl></div>

                        <tfoot id='sX50N'></tfoot>