脚本在Windows 7中成功完成,但不是Win 8.1

时间:2015-07-17 20:21:07

标签: windows sharepoint vbscript windows-7 windows-8.1

我有一个VBScript用于自动续订登录到Microsoft SharePoint站点(Windows任务计划程序每晚运行脚本)。我这样做是因为我有一个映射到SharePoint的网络驱动器,如果没有经常访问该站点,驱动器将失去连接。该脚本在Windows 7中成功执行以下操作:

  1. 打开Internet Explorer
  2. 导航至Sharepoint网站
  3. 输入并提交登录凭据
  4. 等待30秒
  5. 关闭SharePoint IE窗口。
  6. 但是,在Windows 8.1中,脚本似乎在提交凭据后停止,因为窗口无限期地保持打开状态。我希望这里有一些经验丰富的用户可以帮助我改变脚本以避免这种不一致。

    以下是代码:

    On Error Resume Next
    
    Const PAGE_LOADED = 4
    
    Set objIE = CreateObject("InternetExplorer.Application")
    Call objIE.Navigate("https://XXXXXX-my.sharepoint.com")
    objIE.Visible = True
    
    Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(100) : Loop
    
    objIE.Document.all.login.Value = "XXXXXXXX"
    objIE.Document.all.Passwd.Value = "XXXXXXXX"
    
    If Err.Number <> 0 Then
        msgbox "Error: " & err.Description
    
        For Each Button In IE.Document.getElementsByTagName("a")
            If InStr(Button.getAttribute("onclick"), "Sign In()") Then
                Button.Click()
                Exit For
            End If
        Next
    End If
    
    Call objIE.Document.all.credentials.submit
    
    WScript.Sleep 30000
    Set sa = CreateObject("Shell.Application")
    Set windows = sa.Windows()
    
    For Each window In sa.windows
        If left(window.LocationUrl, 5) <> "file:" Then
            ' logic for selecting windows goes here
            If InStr(window.locationUrl,"sharepoint") Then window.Quit()
            If UCase(window.locationUrl) = UCase("about:tabs") Then window.Quit()
        End If
    Next
    
    Set objIE = Nothing
    

0 个答案:

没有答案