直接用winapi就行,别搞那么复杂- #@&cls&powershell "type '%~0'|out-string|iex"&pause&exit
-
-
-
- #Windows API
- $code=@'
- using System.Runtime.InteropServices;
- public static class WinApi{
- [DllImport("user32.dll")]
- public static extern bool SetWindowPos(uint hWnd,uint hAfter,uint x,uint y,uint cx,uint cy,uint flags);
- [DllImport("kernel32.dll")]
- public static extern uint GetConsoleWindow();
- }
- '@
- Add-Type -TypeDefinition $code
- #设置位置及大小
- $hwnd = [WinApi]::GetConsoleWindow()
- [void][WinApi]::SetWindowPos($hwnd,$null,30,30,400,500,0)
-
-
-
-
-
- "hello, world"
-
- cmd /c pause
复制代码
|