|
|
发表于 2024-12-28 14:49:48
|
显示全部楼层
- Add-Type -TypeDefinition @'
- Imports System
- Imports System.Runtime.InteropServices
- Namespace MyCode
- Public Module Win32
- ' 定义常量
- Public Const WM_KEYDOWN As Integer = &H100
- Public Const VK_F5 As Integer = &H74
- ' 导入 FindWindow 函数
- <DllImport("user32.dll", CharSet:=CharSet.Auto)>
- Public Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
- End Function
- ' 导入 PostMessage 函数
- <DllImport("user32.dll", CharSet:=CharSet.Auto)>
- Public Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
- End Function
- ' 导入 GetDesktopWindow 函数
- <DllImport("user32.dll", CharSet:=CharSet.Auto)>
- Public Function GetDesktopWindow() As IntPtr
- End Function
- End Module
- End Namespace
- '@ -Language VisualBasic
- $progman = [MyCode.Win32]::FindWindow("Progman", "Program Manager")
- [MyCode.Win32]::PostMessage($progman, [MyCode.Win32]::WM_KEYDOWN, [MyCode.Win32]::VK_F5, 0)
复制代码 |
|