以梦为马不负青春韶华 2023-03-08 17:40 采纳率: 0%
浏览 21

vbs调用ie浏览器

vbs脚本调用ie浏览器,遇到ie8后,不能置顶ie窗口,请问是为什么
代码如下

MaxBrowserWindow("www.baidu.com")
Sub MaxBrowserWindow(URL)
 With CreateObject("InternetExplorer.Application")
    dim ws
         set ws = CreateObject("Wscript.Shell")
    ws.AppActivate "Internet Explorer"
         .Navigate URL
         While .Busy
         wend
         .Left = 0
         .Top = 0
         .Width = .document.parentWindow.screen.availWidth
         .Height = .document.parentWindow.screen.availHeight
         .Visible = True
 End With
End Sub
  • 写回答

1条回答 默认 最新

  • 「已注销」 2023-03-08 17:54
    关注

    “Devil组”引证GPT后的撰写:、

    • 在IE8浏览器中,应该无法通过调用WSH的AppActivate方法使IE窗口成为活动窗口。这可能是由于IE8中的安全限制或Windows用户账户控制(UAC)的设置引起的。
      用Windows API函数SetForegroundWindow来使IE窗口成为前台窗口,并调用SetWindowPos函数来将IE窗口置顶。

    下面是一个示例代码,使用了Windows API函数:

    MaxBrowserWindow("www.baidu.com")
    
    Sub MaxBrowserWindow(URL)
      Dim ie
      Set ie = CreateObject("InternetExplorer.Application")
      ie.Navigate URL
      ie.Visible = True
      
      ' wait for the page to load
      Do While ie.Busy Or Not ie.ReadyState = 4
        WScript.Sleep 100
      Loop
    
      ' set window position and size
      ie.Left = 0
      ie.Top = 0
      ie.Width = ie.document.parentWindow.screen.availWidth
      ie.Height = ie.document.parentWindow.screen.availHeight
      
      ' bring the window to the foreground and set it as topmost
      Dim hwnd
      hwnd = ie.HWND
      SetForegroundWindow hwnd
      SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    
    End Sub
    
    ' Windows API declarations
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Private Const HWND_TOPMOST = -1
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    
    
    

    此代码需要在管理员权限下运行才能使用Windows API函数。

    评论

报告相同问题?

问题事件

  • 创建了问题 3月8日