powershell - 将PowerShell命令转换为脚本

标签 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脚本是什么?

最佳答案

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)

关于powershell - 将PowerShell命令转换为脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52302191/

相关文章:

python - 为什么 powershell 和 python 对同一命令给出不同的结果?

powershell - 从 PowerShell 运行 MsiExec 并获取返回代码

c# - 如何将json字典序列化/反序列化为数组

powershell - 为什么 $false -eq ""是真的?

sql-server - 如何通过SQL Powershell在所有存储过程中搜索字符串?

powershell - SaltStack : run powershell script in a state

windows - 如何检测调用powershell脚本的批处理文件是否由Windows启动事件运行

powershell - 如何从 Azure 门户将域委托(delegate)给 Azure DNS?

csv - 为 CSV 数据创建可编辑的 powershell GUI

powershell - 如何在Mercurial中打印特定文件的所有修订的内容?