本帖最后由 flashercs 于 2019-11-21 16:23 编辑
批处理.bat- <#*,:&cls
- @echo off
- pushd "%~dp0"
- Powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- popd
- pause
- exit /b
- #>
- $x = 300
- $y = 200
- $xsize = 300
- $ysize = 200
- $app = "cmd.exe"
- $params = @('/k', 'echo hello&echo Lee')
-
- Add-Type -TypeDefinition @'
- using System;
- using System.Runtime.InteropServices;
- namespace User32
- {
- public static class NativeMethods
- {
- [DllImport("user32.dll",EntryPoint = "SetWindowPos",SetLastError = true)]
- public static extern Boolean SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, UInt32 uFlags);
-
- }
- }
-
- '@
-
- $proc = Start-Process -FilePath $app -ArgumentList $params -PassThru
- while ($proc.MainWindowHandle -eq 0) {
- Start-Sleep -Milliseconds 10
- }
-
- [User32.NativeMethods]::SetWindowPos($proc.MainWindowHandle, 0, $x, $y, $xsize, $ysize, 0x4000 + 0x0004)
复制代码
|