【问题标题】:Convert PowerShell Command to Script将 PowerShell 命令转换为脚本
【发布时间】:2018-09-12 19:33:20
【问题描述】:

当从批处理文件(或命令提示符)运行时,下面的 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 脚本是什么?

【问题讨论】:

    标签: powershell


    【解决方案1】:
    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)
    

    【讨论】:

    • [Win32Functions.Win32SendMessage]::SendMessage(-1,0x0112,0xF170,-1) 打开显示器。
    猜你喜欢
    • 2021-11-16
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 2016-08-26
    • 2013-11-04
    • 2010-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多