如何在C#应用程序中使用Shell32?

Lis*_*isa 29 c# shell32

为了使Shell32工作,我应该在C#应用程序中包含哪些内容?

编辑:

我的应用程序无法识别shell32.我应该包括哪些参考或库?我想要做的是:

Shell32.Shell shell = new Shell32.Shell(); 
Run Code Online (Sandbox Code Playgroud)

我得到的是一个错误:

错误1找不到类型或命名空间名称"Shell32"(您是否缺少using指令或程序集引用?)

Vas*_*ich 50

只是Shell32.dll,以Windows\System32形成Shell32.dll文件夹,并使用它:

Shell32.Shell shell = new Shell32.Shell();
shell.MinimizeAll();
Run Code Online (Sandbox Code Playgroud)

  • 您还可以在Visual Studio 2010及更高版本的*Reference Manager*(*添加引用*对话框窗口)中的COM选项卡中添加对*Microsoft Shell控件和Automation*的引用...但不确定哪些早期版本具有此功能. (11认同)

xam*_*mir 47

也许这可以帮助:

  1. 右键单击项目
  2. 点击 Add reference
  3. 点击.COM制表Add reference对话
  4. 选择 Microsoft Shell Controls and Automation
  5. 点击 OK

shell32准备好了......


Du *_* D. 26

我知道这个帖子已经老了,但是我发布这个帖子给任何有同样问题的人都这样做了.上面的解决方案不能在Windows 8下编译

Shell32.Shell shell = new Shell32.Shell(); <=这不适用于Windows 8

如果您希望应用程序在Windows 8下运行,请使用下面的解决方法.

using Shell32;

private Shell32.Folder GetShell32Folder(string folderPath)
{
    Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
    Object shell = Activator.CreateInstance(shellAppType);
    return (Shell32.Folder)shellAppType.InvokeMember("NameSpace",
    System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folderPath });
}
Run Code Online (Sandbox Code Playgroud)

  • 我绝对不打算抄袭答案,我只是不记得从哪里得到它,旁边我不认为我从那里得到它.快速搜索谷歌,这个解决方案随处可见,其中一些甚至比您提供的链接更旧.我不知道该怎么说.http://techitongue.blogspot.ca/2012/06/shell32-code-compiled-on-windows-7.html (9认同)
  • 您的答案看起来非常像[Windows 8中的Instantiate Shell32.Shell对象]的答案(https://social.msdn.microsoft.com/Forums/vstudio/en-US/b25e2b8f-141a-4a1c-a73c Visual Studio论坛中的-1cb92f953b2b/instantiate-shell32shell-object-in-windows-8?forum = clr)问题.虽然您欢迎更新此问题的情绪,但在没有提供链接的情况下显示其他人的工作称为抄袭,并且不会*欢迎使用Stack Overflow.如果是这种情况,请编辑您的答案并提供某种归属. (4认同)
  • 很公平,但在将来,请在展示其他人的工作时提供归因. (2认同)

gon*_*ins 6

  1. 在解决方案资源管理器中右键单击您的项目.
  2. 从下拉菜单中选择"添加参考...".
  3. 单击"浏览"选项卡.
  4. 导航到C:\ Windows\System32目录.
  5. 选择"shell32.dll"文件.然后按"确定"按钮.

您现在有了使用Shell32.Shell的适当参考.


Edw*_*rey 5

将 COM 库Microsoft Shell Controls and Automation的引用添加到您的项目中。此外,请确保使用的代码Shell32.Shell在单线程单元中运行,例如通过将[STAThread]属性添加到Main.