在 VBS 中最大化 IE 窗口

在 VBS 中最大化 IE 窗口

错误需要帮助在 VB 脚本中最大化 IE 窗口。尝试了几种方法但都无济于事。

Option Explicit


Dim objApp, nIE, oIE, Window

Set objApp = CreateObject("Shell.Application")
Set oIE = Nothing


For Each Window In objApp.Windows
If InStr(Window.Name, "Internet Explorer") Then
Set oIE = Window
End If
Next

If oIE Is Nothing Then
Call NewIE
Else
Call OpenIE
End If


'Internet Explorer is closed.
Sub NewIE()
Set nIE = CreateObject("InternetExplorer.Application")
nIE.Navigate2 "https://www.bbc.com"
nIE.Navigate2 "https://www.microsoft.com/en-us/microsoft- 
365/onedrive/online-cloud-storage", 4096
nIE.Visible = True

End Sub

'Internet Explorer is already opened.
 Sub OpenIE()
 oIE.Navigate2 "https://www.bbc.com", 2048
 oIE.Navigate2 "https://www.microsoft.com/en-us/microsoft- 
 365/onedrive/online-cloud-storage", 4096
 oIE.Visible = True

 End Sub

答案1

有关 IE 对象的信息,IE 对象

问题在于 IE 是否全屏启动取决于注册表设置或组策略,而 vbscript 可能无法访问这两者,因为它们需要提升的权限。参考最大化 IE

如果“最大化”按钮可见,则 tek-tips 方法将会起作用。

答案2

只需将nIE.FullScreen = True和添加oIE.FullScreen = True到您的脚本中:

Option Explicit
Dim objApp, nIE, oIE, Window
Set objApp = CreateObject("Shell.Application")
Set oIE = Nothing

For Each Window In objApp.Windows
  If InStr(Window.Name, "Internet Explorer") Then
    Set oIE = Window
  End If
Next

If oIE Is Nothing Then
  Call NewIE
Else
  Call OpenIE
End If

'Internet Explorer is closed.
Sub NewIE()
Set nIE = CreateObject("InternetExplorer.Application")
nIE.Navigate2 "https://www.bbc.com"
nIE.Navigate2 "https://www.microsoft.com/en-us/microsoft-365/onedrive/online-cloud-storage", 4096
nIE.Visible = True
nIE.FullScreen = True
End Sub

'Internet Explorer is already opened.
 Sub OpenIE()
 oIE.Navigate2 "https://www.bbc.com", 2048
 oIE.Navigate2 "https://www.microsoft.com/en-us/microsoft-365/onedrive/online-cloud-storage", 4096
 oIE.Visible = True
 oIE.FullScreen = True
 End Sub

请注意,许多网站不再适用于 IE,而且许多现在可以运行的网站在不久的将来可能无法运行。

相关内容