从 PowerShell 调用 Windows Shell 函数? [英] Calling Windows Shell Functions from PowerShell?
问题描述
所以我一直在学习本教程:
So I was following this tutorial:
https://msdn.microsoft.com/en-us/library/windows/desktop/hh127427(v=vs.85).aspx
当我偶然看到调用 SHChangeNotify 函数"这句话时.我该怎么做呢?PowerShell 无法识别它.我是否必须在 C++ 中导入一些库并从 C++ 程序中调用它?我使用的是 Windows 10.
when I cam across the sentence that casually says "Call the SHChangeNotify function". How do I do this? It is not recognized by powershell. Do I have to import some library in c++ and call it from a c++ program? I am on windows 10.
推荐答案
我使用以下 C# 代码从 Powershell 调用桌面刷新:
I used the following to call a refresh on the desktop from powershell by using C# code:
$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()
希望这有助于任何仍在寻找答案的人,因为 SimonS 提供的链接似乎不再有效.
Hope this helps anyone still looking for an answer as the link provided by SimonS doesn't seem to work anymore.
附言这是我从 IDERA - Refreshing Icon 中得到的想法的地方缓存
这篇关于从 PowerShell 调用 Windows Shell 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!