批处理之家's Archiver

psstudio 发表于 2019-11-21 13:02

vbs修改调用窗口大小在win10下不生效?

一段VBS代码:
Option Explicit
Dim objWMIService
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim objStartupInfo
Set objStartupInfo = objWMIService.Get("Win32_ProcessStartup")
objStartupInfo.SpawnInstance_
objStartupInfo.X = 300
objStartupInfo.XSize = 300
objStartupInfo.Y = 500
objStartupInfo.YSize = 200
Dim objNewProcess
Set objNewProcess = objWMIService.Get("Win32_Process")
Dim intPID
Dim errRtn
errRtn = objNewProcess.Create("cmd.exe", Null, objStartupInfo, intPID)
指定运行程序的位置和窗口大小,在WIN7下测试通过,为什么在WIN10上只能修改位置,窗口大小改不了? 求大神

flashercs 发表于 2019-11-21 14:30

win10真不行,notepad.exe 连窗口位置都无法修改.得用别的方法

psstudio 发表于 2019-11-21 15:46

别的方法? 除了改注册表,第三方。没其它的办法了吧。

flashercs 发表于 2019-11-21 16:13

[i=s] 本帖最后由 flashercs 于 2019-11-21 16:23 编辑 [/i]

批处理.bat[code]<#*,:&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)[/code]

9zhmke 发表于 2020-8-21 17:58

要加延时才行,试过了可以用

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.