[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] 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上只能修改位置,窗口大小改不了? 求大神

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

TOP

本帖最后由 flashercs 于 2019-11-21 16:23 编辑

批处理.bat
  1. <#*,:&cls
  2. @echo off
  3. pushd "%~dp0"
  4. Powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
  5. popd
  6. pause
  7. exit /b
  8. #>
  9. $x = 300
  10. $y = 200
  11. $xsize = 300
  12. $ysize = 200
  13. $app = "cmd.exe"
  14. $params = @('/k', 'echo hello&echo Lee')
  15. Add-Type -TypeDefinition @'
  16. using System;
  17. using System.Runtime.InteropServices;
  18. namespace User32
  19. {
  20.    public static class NativeMethods
  21.     {
  22.         [DllImport("user32.dll",EntryPoint = "SetWindowPos",SetLastError = true)]
  23.         public static extern Boolean SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, UInt32 uFlags);
  24.         
  25.     }
  26. }
  27. '@
  28. $proc = Start-Process -FilePath $app -ArgumentList $params -PassThru
  29. while ($proc.MainWindowHandle -eq 0) {
  30.   Start-Sleep -Milliseconds 10
  31. }
  32. [User32.NativeMethods]::SetWindowPos($proc.MainWindowHandle, 0, $x, $y, $xsize, $ysize, 0x4000 + 0x0004)
复制代码
微信:flashercs
QQ:49908356

TOP

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

TOP

win10真不行,notepad.exe 连窗口位置都无法修改.得用别的方法
微信:flashercs
QQ:49908356

TOP

返回列表