将PowerShell命令转换为脚本

时间:2018-09-12 19:33:20

标签: powershell

从批处理文件(或命令提示符)运行时,以下PowerShell命令将关闭屏幕。我希望将其作为PowerShell脚本运行。

  

Turn Off Screen - TechNet Script Center

     

powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)

我查看了Add-Type - Microsoft Docs,但是我无法正确获取参数。

与此等效的PowerShell脚本是什么?

1 个答案:

答案 0 :(得分:3)

Add-Type -MemberDefinition @"
    [DllImport("user32.dll")]
    public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
"@  -Name "Win32SendMessage" -Namespace "Win32Functions"

[Win32Functions.Win32SendMessage]::SendMessage(-1,0x0112,0xF170,2)
相关问题