从 PowerShell 调用 Windows Shell 函数?

Sea*_*dre 4 registry shell powershell windows-10

所以我正在遵循这个教程:

https://msdn.microsoft.com/en-us/library/windows/desktop/hh127427(v=vs.85).aspx

当我偶然发现“调用 SHChangeNotify 函数”这句话时。我该怎么做呢?powershell 无法识别它。我是否必须在 C++ 中导入一些库并从 C++ 程序中调用它?我在 Windows 10 上。

mem*_*eam 5

我使用以下 C# 代码从 powershell 调用桌面刷新:

  $code = @'
  [System.Runtime.InteropServices.DllImport("Shell32.dll")] 
  private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);

  public static void Refresh()  {
      SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);    
  }
'@

Add-Type -MemberDefinition $code -Namespace WinAPI -Name Explorer 
[WinAPI.Explorer]::Refresh()
Run Code Online (Sandbox Code Playgroud)

希望这对仍在寻找答案的人有所帮助,因为 SimonS 提供的链接似乎不再有效。

ps 这是我从 IDERA 那里得到的想法- 刷新图标缓存