- Add-Type -TypeDefinition @'
- using System;
- using System.Runtime.InteropServices;
- namespace MyCode
- {
- public static class Win32
- {
- public const int WM_KEYDOWN = 0x100;
- public const int VK_F5 = 0x74;
-
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
-
- [DllImport("user32.dll",CharSet = CharSet.Auto)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
-
- [DllImport("user32.dll",CharSet = CharSet.Auto)]
- public static extern IntPtr GetDesktopWindow();
-
- }
- }
- '@
- $progman = [MyCode.Win32]::FindWindow("Progman", "Program Manager")
- [MyCode.Win32]::PostMessage($progman, [MyCode.Win32]::WM_KEYDOWN, [MyCode.Win32]::VK_F5, 0)
复制代码
|