如何改变外部程序的窗体位置和大小?


PowerShell交流中心分类: Powershell基础如何改变外部程序的窗体位置和大小?
0
tjhgchg asked 6 年 ago

学习了很久,也无解?

tjhgchg replied 6 年 ago

能给一个如何用这个函数的例子么?

Mooser Lee 管理员 replied 6 年 ago

Get-Process powershell | Set-Window -X 2040 -Y 142 -Passthru

tjhgchg replied 6 年 ago

Set-Window : 无法将“Set-Window”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请
确保路径正确,然后再试一次。
所在位置 行:1 字符: 26
+ Get-Process powershell | Set-Window -X 2040 -Y 142 -Passthru
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-Window:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Mooser Lee 管理员 replied 6 年 ago

你要把我发的链接中的脚本下载下来,执行一遍,再试试。

tjhgchg replied 6 年 ago

已经下载了 放在了同一目录

tjhgchg replied 6 年 ago

Get-Process powershell | .\Set-Window -X 2040 -Y 142 -Passthru
这样执行不报错,但是没有任何效果

tjhgchg replied 6 年 ago

PS C:\> .\Set-Window powershell -X 2040 -Y -Width 100 -Height 142 -Passthru
PS C:\>

Mooser Lee 管理员 replied 6 年 ago

先在控制台中导入函数: . .\Set-Window

Mooser Lee 管理员 replied 6 年 ago

记得是 一个点,中间空格, 然后是脚本文件的路径。

tjhgchg replied 6 年 ago

think ,is ok

tjhgchg replied 6 年 ago

再问一下能通过进程号改变窗体位置和大小么

Mooser Lee 管理员 replied 6 年 ago

Get-Process -Id $PID

tjhgchg replied 6 年 ago

再问一下,如何外部程序窗体改变窗口最大化、普通、最小化的代码?多谢了

tjhgchg replied 6 年 ago

[DllImport(“User32.dll”)]
public extern static bool ShowWindow(IntPtr handle, int cmdShow);

…….
$Return = [Window]::ShowWindow($Handle, 3)
我自己改了一下,报错:
方法调用失败,因为 [Window] 不包含名为“ShowWindow”的方法。
所在位置 C:\Set-Window.ps1:101 字符: 13
+ $Return = [Window]::ShowWindow($Handle, 3)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [],RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

tjhgchg replied 6 年 ago

搞定了

1 Answers
0
Best Answer
Mooser Lee 管理员 answered 6 年 ago