当我在兼容模式下运行我的脚本时,我收到以下错误?

时间:2014-05-23 05:15:46

标签: internet-explorer-10 autoit

我想自动化自动网络登录这个代码使用ie9和一些表单(使用表单标签开发)很好。但是当我为使用标签表构建的表单运行相同的脚本时,它是在Ie10,windows8中没有使用id,但是相同的脚本使用IE9 windows7的id,但是在我的工作环境中,现在我们主要使用windows8机器。所以我开始知道,如果我们在兼容模式下运行,我可以解决问题,当我添加代码在兼容模式下运行时,我收到此错误。我不明白该怎么做..

#include <IE.au3>
    #include <GuiButton.au3>
    #include <File.au3>
    #RequireAdmin

        If IsAdmin() then
        $64Bit = ""
            If @OSArch = "X64" Then
                $64Bit = "64"
            EndIf
        If StringLeft(RegRead("HKLM" & $64Bit & "\SOFTWARE\Microsoft\Internet Explorer\Version Vector", "IE"), 1) > 8 Then ;Check for version 9 or later


          $wshNetwork = ObjCreate("WScript.Network")
          $struser = $wshNetwork.Username
          $objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
          $objAcc = $objWMIService.Get('Win32_UserAccount.Name="' & $struser & '",Domain="' & @ComputerName & '"')
          $objAccount = $objAcc.SID
          RegWrite("HKU" & $64Bit & "\" & $objAccount & "\Software\Microsoft\Internet Explorer\BrowserEmulation\", "AllSitesCompatibilityMode", "REG_DWORD", 1)
          RegWrite("HKU\" & $objAccount & "\Software\Microsoft\Internet Explorer\BrowserEmulation\", "AllSitesCompatibilityMode", "REG_DWORD", 1)
        EndIf
        EndIf

    $url = "https://190.198.14.15/"
    $formID = ""
    $formUID = "username"
    $uName = "admin"
    $formPID = "password"
    $pwd = "SeR^ER@iL0"
    $formSubmit = "ID_LOGON"

    ;Launch the Internet Explorer as a private session
    ShellExecute ("iexplore.exe", " -private about:blank", @programFilesDir & "\Internet Explorer\iexplore.exe", "open", @SW_MAXIMIZE)
    WinWait ("Blank Page")
    $oIE = _IEAttach ("about:blank", "url")

    ;Wait for the IE to launch
    _IELoadWait ($oIE)

    ;Navigate to the given URL
    _IENavigate ($oIE, $url)

    ;Get the IE process id specific to this instance
    Local $PID = WinGetProcess(_IEPropertyGet($oIE, "hwnd"))

    ;Print the PID in the console
    If $PID Then
        ;MsgBox(0, "Example", "Internet Explorer is running.")
        ;MsgBox(0,"Process ID",$PID)
        ConsoleWrite("["&$PID&"]")
    Else
        MsgBox(0, "Example", "Unable to get the process id of IE instance")
    EndIf

    ;Disable IE address bar and menu bar
    _IEPropertySet ($oIE, "addressbar", False)
    _IEPropertySet ($oIE, "menubar", False)

    ;Click on 'Continue to this website' option if there is any HTTPS certificate Warning
    while(_IELinkClickByText ($oIE, "Continue to this website (not recommended)."))
            _IELoadWait ($oIE,10000)
    wend

    ;Get the field id and fill with provided value
    ;$oIE.document.getElementById($formUID).value = $uName
    $oIE.document.getElementsByName($formUID).Item(0).value = $uName
    $oIE.document.getElementById($formPID).value = $pwd

    ;$oSubmit = _IEGetObjByName ($oIE, $formSubmit)
    $oSubmit = $oIE.document.getElementById($formSubmit)
    _IEAction ($oSubmit, "click")

当我正在运行时,我收到错误:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\My_Files\Automation scripts\My tests\AutomaticWebpageLogin -1.au3"    
"D:\My_Files\Automation scripts\My tests\AutomaticWebpageLogin -1.au3" (18) : ==> Variable must be of type "Object".:
$objAccount = $objAcc.SID
$objAccount = $objAcc^ ERROR
>Exit code: 1    Time: 0.697

1 个答案:

答案 0 :(得分:0)

您的身份验证过程中出现错误($objAcc =行),可能是密码或用户名错误。

如果发生错误,WMI服务的.Get函数不会返回对象。

检查这样的错误

if(@error <> 0) Then
  ; ERROR HANDLER
EndIf 

并检查帐户信息是否正确。 Look at your other question

参考Win32_UserAccount