如何使用VBScript修复window.moveTo上的类型不匹配错误?

时间:2017-11-01 13:29:09

标签: vbscript windows-10 hta

此处的所有内容在Windows 7上运行正常。在Windows 10上,window.MoveTo intLeft, intTop出现类型不匹配错误。

Sub Window_OnLoad
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    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

1 个答案:

答案 0 :(得分:0)

所以问题是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
相关问题