这里的一切都在Windows 7上运行良好。在 Windows 10 上,我们收到 window.MoveTo intLeft, intTop
的类型不匹配错误 .
Sub Window_OnLoad
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
For Each objItem in colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
intLeft = (intHorizontal - 670) / 2
intTop = (intVertical - 325) / 2
window.ResizeTo 670,325
window.MoveTo intLeft, intTop
End Sub
所以问题objWMIService
.我想它在 Windows 10 中的工作方式不同。
这是我发现的一个功能,似乎工作得很好。
array_ScreenRes = GetScreenResolution
intHorizontal = array_ScreenRes(0)
intVertical = array_ScreenRes(1)
Function GetScreenResolution()
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.Navigate("about:blank")
Do Until .ReadyState = 4: WScript.Sleep 100: Loop
width = .Document.ParentWindow.Screen.Width
height = .document.ParentWindow.Screen.Height
End With
oIE.Quit
GetScreenResolution = Array(width, height)
End Function