问题描述
我一直在尝试从SHDocVw.Internet Explorer处理IE事件.为此,我在Visual Studio项目中添加了对C:\ windows \ system32 \ ShDocVw.dll的引用,该引用在编译时会自动生成Interop.ShDocVw.dll
I've been trying to handle IE events from SHDocVw.Internet Explorer. To do this I added a reference to C:\windows\system32\ShDocVw.dll in a Visual Studio project, which when compiled automatically generated Interop.ShDocVw.dll
我无法直接在PowerShell中直接初始化SHDocVw.InternetExplorer,有关我的问题的更多信息
I was unable to initialize SHDocVw.InternetExplorer directly in PowerShell, some more info on my issue here
PowerShell版本信息
PowerShell Version Info
PS C:\Users\chentiangemalc> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.103
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.103
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
我正在使用的当前代码
[System.Reflection.Assembly]::LoadFrom("C:\support\IeAutomator\Interop.SHDocVw.dll")
$code = @'
using System;
using System.Collections.Generic;
using System.Text;
public static class IE
{
public static SHDocVw.InternetExplorer GetIE()
{
var target = new SHDocVw.InternetExplorer();
return target;
}
}
'@
Add-Type -TypeDefinition $code -ReferencedAssemblies "C:\support\IeAutomator\Interop.SHDocVw.dll"
$ie = [IE]::GetIE()
$navigateComplete2 = Register-ObjectEvent -InputObject $ie -EventName "NavigateComplete2" -SourceIdentifier "IE.NavigateComplete2"
$ie.Visible = $true
$ie.Navigate("http://www.google.com.au")
Wait-Event -SourceIdentifier "IE.NavigateComplete2"
在google.com.au加载后,似乎发生了崩溃,因此当我期望NavigateComplete2事件将被触发时.
Crash seems to occur after google.com.au has loaded, so when I expect the NavigateComplete2 event would be firing.
我也尝试过
$ie.add_NavigateComplete2({ Write-Host "NavigateComplete2!" })
但这根本没有触发.在WinDbg下运行:
But this did not trigger at all.Run under WinDbg :
1:006> !analyze -v
*******************************************************************************
* *
* Exception Analysis *
* *
*******************************************************************************
*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_64\Microsoft.Pb378ec07#\82473b57141194bcb8c2b3e31479e32d\Microsoft.PowerShell.ConsoleHost.ni.dll
*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_64\Microsoft.P521220ea#\179a8ea61a118e0c51c9acc481b8fb86\Microsoft.PowerShell.Commands.Utility.ni.dll
Failed to switch to target 0
GetUrlPageData2 (WinHttp) failed: 12002.
DUMP_CLASS: 2
DUMP_QUALIFIER: 0
FAULTING_IP:
clr!JIT_IsInstanceOfClass2+1e
00007ff8`5bea3bae 488b5210 mov rdx,qword ptr [rdx+10h]
EXCEPTION_RECORD: (.exr -1)
ExceptionAddress: 00007ff85bea3bae (clr!JIT_IsInstanceOfClass2+0x000000000000001e)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 0000000000000000
Parameter[1]: ffffffffffffffff
Attempt to read from address ffffffffffffffff
FAULTING_THREAD: 00003f50
DEFAULT_BUCKET_ID: INVALID_POINTER_READ
PROCESS_NAME: powershell.exe
ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.
EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.
EXCEPTION_CODE_STR: c0000005
EXCEPTION_PARAMETER1: 0000000000000000
EXCEPTION_PARAMETER2: ffffffffffffffff
FOLLOWUP_IP:
clr!JIT_IsInstanceOfClass2+1e
00007ff8`5bea3bae 488b5210 mov rdx,qword ptr [rdx+10h]
READ_ADDRESS: ffffffffffffffff
BUGCHECK_STR: INVALID_POINTER_READ
WATSON_BKT_PROCSTAMP: 57899aad
WATSON_BKT_PROCVER: 10.0.14393.0
PROCESS_VER_PRODUCT: Microsoft® Windows® Operating System
WATSON_BKT_MODULE: clr.dll
WATSON_BKT_MODSTAMP: 575a1507
WATSON_BKT_MODOFFSET: 3bae
WATSON_BKT_MODVER: 4.6.1586.0
MODULE_VER_PRODUCT: Microsoft® .NET Framework
BUILD_VERSION_STRING: 10.0.14393.0 (rs1_release.160715-1616)
MODLIST_WITH_TSCHKSUM_HASH: 0dd991ed9eff5611cdfb10e932a26711163d1273
MODLIST_SHA1_HASH: cdcd900a67a9c62dc8ee8eebfc73dc865306c7d9
NTGLOBALFLAG: 70
APPLICATION_VERIFIER_FLAGS: 0
PRODUCT_TYPE: 1
SUITE_MASK: 272
MISSING_CLR_SYMBOL: 0
ANALYSIS_SESSION_HOST: DESKTOP-NC2T50T
ANALYSIS_SESSION_TIME: 09-13-2016 09:21:52.0518
ANALYSIS_VERSION: 10.0.14321.1024 amd64fre
MANAGED_CODE: 1
MANAGED_ENGINE_MODULE: clr
MANAGED_ANALYSIS_PROVIDER: SOS
MANAGED_THREAD_ID: 3f50
THREAD_ATTRIBUTES:
OS_LOCALE: ENA
PROBLEM_CLASSES:
INVALID_POINTER_READ
Tid [0x3f50]
Frame [0x00]: clr!JIT_IsInstanceOfClass2
LAST_CONTROL_TRANSFER: from 00007ff82fa2058e to 00007ff85bea3bae
STACK_TEXT:
000000d2`42bfc148 00007ff8`2fa2058e : 00007ff8`5c5d48d8 00007ff8`5bfb47e6 0018029c`52a286b0 00007ff8`5bec4200 : clr!JIT_IsInstanceOfClass2+0x1e
000000d2`42bfc150 00007ff8`2e4b9b01 : 00007ff7`fcaf8040 000000d2`42bfc300 000000d2`42bfc4b8 000000d2`42bfc3e8 : System_Management_Automation_ni+0x1e2058e
000000d2`42bfc1b0 00007ff7`fc8cb2fd : 000000d2`42bfc410 000000d2`42bfc4b8 000000d2`42bfc3e8 000000d2`42bfc8b0 : System_Management_Automation_ni+0x8b9b01
000000d2`42bfc240 00007ff8`5bea6a53 : 0000029c`54baf7b0 0000029c`54c5aee0 0000029c`54c6abf0 00007ff8`5c5b8948 : 0x00007ff7`fc8cb2fd
000000d2`42bfc290 00007ff8`5bea6913 : 00007ff8`593816b8 00000000`00000000 0000029c`54c6abf0 80003ffb`fe57e1e0 : clr!CallDescrWorkerInternal+0x83
000000d2`42bfc2d0 00007ff8`5bfecace : 00000000`00000000 00000000`00000000 000000d2`42bfc4b8 00007ff8`58d05352 : clr!CallDescrWorkerWithHandler+0x4e
000000d2`42bfc310 00007ff8`5bfec977 : 00007ff8`58d05352 00007ff8`59381c98 00000000`00000000 00007ff7`fcaf8040 : clr!CallDescrWorkerReflectionWrapper+0x1a
000000d2`42bfc360 00007ff8`59235230 : 000000d2`02000000 000000d2`42bfcb48 00000000`00000000 0000029c`54c5c800 : clr!RuntimeMethodHandle::InvokeMethod+0x567
000000d2`42bfc940 00007ff8`59234d32 : 0000029c`54764d68 00000000`00000000 00000000`00000000 000000d2`00000000 : mscorlib_ni+0x535230
000000d2`42bfc9b0 00007ff8`5bea6a53 : 0000029c`54c110c0 0000029c`54bb0018 00007ff8`00040100 0000029c`54764d68 : mscorlib_ni+0x534d32
000000d2`42bfca30 00007ff8`5bea6913 : 000000d2`42bfd248 00007ff8`5c06b8ac 000000d2`42bfd248 00000000`00000000 : clr!CallDescrWorkerInternal+0x83
000000d2`42bfca80 00007ff8`5bea7165 : 00000000`00000006 000000d2`42bfd5b0 000000d2`42bfdaa0 000000d2`42bfd248 : clr!CallDescrWorkerWithHandler+0x4e
000000d2`42bfcac0 00007ff8`5bfa3674 : 000000d2`42bfdb30 00000000`00040100 000000d2`42bfdb30 00000000`00040100 : clr!MethodDescCallSite::CallTargetWorker+0xf8
000000d2`42bfcbd0 00007ff8`5bfa31d6 : 00007ff8`00000006 00000002`00000002 00002001`0000001d 000000d2`42bfd720 : clr!DispatchInfo::InvokeMemberWorker+0xad8
000000d2`42bfd780 00007ff8`5bfa3afd : 00000000`00000000 0000029c`6c89ab30 00000000`00000000 000000d2`42bfd9a0 : clr!DispatchInfo::InvokeMemberDebuggerWrapper+0x1c6
000000d2`42bfd8e0 00007ff8`5bfa3ec6 : 0000029c`6cad8420 00000000`00000000 0000029c`542efe20 0000029c`6cabed30 : clr!DispatchInfo::InvokeMember+0x467
000000d2`42bfdbd0 00007ff8`5bfa3d2d : 0000029c`542efe00 0000029c`6cadbe8c 000000d2`42bfdd80 00000000`000000fc : clr!InternalDispatchImpl_Invoke+0x1ed
000000d2`42bfdcf0 00007ff8`5bfa3c6e : 0000029c`6cac1fa0 0000029c`6cad9888 00007ff8`00000000 00007ff8`00000000 : clr!InternalDispatchImpl_Invoke_CallBack+0xb2
000000d2`42bfdd50 00007ff8`6c785664 : 00000000`00000000 0000029c`6cadbf54 0000029c`6c89ab30 00007ff8`6c796db2 : clr!InternalDispatchImpl_Invoke_Wrapper+0xf8
000000d2`42bfddf0 00007ff8`6c784840 : 000000d2`42bfe340 00007ff8`000000fc 000000d2`42bfe780 00000000`00000000 : OLEAUT32!IDispatch_Invoke_Stub+0xd4
000000d2`42bfde80 00007ff8`6d4349f0 : 000000d2`42bfe050 000000d2`42bfe340 00007ff8`6c799ea2 000000d2`42bfe780 : OLEAUT32!IDispatch_RemoteInvoke_Thunk+0x60
000000d2`42bfdef0 00007ff8`6d042260 : 00007ff8`6c796a10 0000029c`6cac4930 00000000`00000000 00007ff8`5c2b76e7 : RPCRT4!NdrStubCall2+0x990
000000d2`42bfe590 00007ff8`6c7747ce : 0000029c`00000001 000000d2`42bfe780 0000029c`6cac4908 0000029c`542efe00 : combase!CStdStubBuffer_Invoke+0xb0
000000d2`42bfe5d0 00007ff8`6d08de2c : 00000000`00000000 0000029c`542efe20 000000d2`42bfe780 00000000`00000000 : OLEAUT32!CDispStubWrapper::Invoke+0x11e
000000d2`42bfe620 00007ff8`6d08e472 : 0000029c`00000000 000000d2`42bfe790 000000d2`42bfe700 00007ff8`6d557ad7 : combase!ObjectMethodExceptionHandlingAction<<lambda_76d9e92c799d246a4afbe64a2bf5673d> >+0x4c
000000d2`42bfe680 00007ff8`6d0a5e18 : 0000029c`6cac1ad0 000000d2`42bfea20 0000029c`6cac48d0 0000029c`6ca45488 : combase!DefaultStubInvoke+0x222
000000d2`42bfe8a0 00007ff8`6d0a3e1d : 00000000`00000000 00000000`00000000 0000007f`00000904 0000029c`6cac1a00 : combase!ServerCall::ContextInvoke+0x448
000000d2`42bfeb80 00007ff8`6d0a2574 : 0000029c`6cac3d30 0000029c`6cac1720 0000029c`6cac1720 0000029c`fffffff4 : combase!AppInvoke+0x32d
000000d2`42bfecf0 00007ff8`6d0a17fc : 0000029c`6cac18f0 0000029c`6cac1720 0000029c`52a10000 0000029c`6cac1720 : combase!ComInvokeWithLockAndIPID+0x574
000000d2`42bfef60 00007ff8`6d44a194 : 0000029c`52a10000 00000000`00000000 00007ff8`6d2138f0 00000000`00000000 : combase!ThreadInvoke+0xe2c
000000d2`42bff1a0 00007ff8`6d4490ad : 00000000`00000000 00000000`00000000 000000d2`42bff3c0 00007ff8`6a88e2eb : RPCRT4!DispatchToStubInCNoAvrf+0x24
000000d2`42bff1f0 00007ff8`6d449bfe : 0000029c`6cac3c74 000000d2`42bff3c0 00000060`00000000 00000000`00000000 : RPCRT4!RPC_INTERFACE::DispatchToStubWorker+0x1bd
000000d2`42bff2c0 00007ff8`6d429927 : 0000029c`6cadbdc0 00000000`00000000 0000029c`6cac7db0 00000000`00000001 : RPCRT4!RPC_INTERFACE::DispatchToStubWithObject+0x15e
000000d2`42bff360 00007ff8`6d429f7c : 00000000`0660cbd5 0000029c`6cac3a70 000000d2`42bff509 0000029c`6cac3a70 : RPCRT4!LRPC_SCALL::DispatchRequest+0x177
000000d2`42bff440 00007ff8`6d44426c : 00000000`00000000 0000029c`6cac37a0 00000000`00000000 00000000`00000000 : RPCRT4!LRPC_SCALL::HandleRequest+0x2bc
000000d2`42bff560 00007ff8`6d445acb : 0000029c`6c88c9e0 0000029c`6c88c9e0 0000029c`00000001 0000029c`6c88c9e0 : RPCRT4!LRPC_ADDRESS::HandleRequest+0x36c
000000d2`42bff610 00007ff8`6d4385ca : 00000000`00000001 000000d2`42bffab8 00000000`00000000 00007ff8`6d4e0f74 : RPCRT4!LRPC_ADDRESS::ProcessIO+0x91b
000000d2`42bff750 00007ff8`6d5525fe : 00000000`00000000 00007ff8`00000001 00000000`7ffe03b0 00000000`00000000 : RPCRT4!LrpcIoComplete+0xaa
000000d2`42bff7f0 00007ff8`6d5530d9 : 00000000`00000004 0000029c`6c88dc00 0000029c`6c893910 00000000`00000000 : ntdll!TppAlpcpExecuteCallback+0x25e
000000d2`42bff8a0 00007ff8`6cd98364 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!TppWorkerThread+0x8d9
000000d2`42bffca0 00007ff8`6d585e91 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14
000000d2`42bffcd0 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21
THREAD_SHA1_HASH_MOD_FUNC: 6f313d77ee52b1c452e91a9959f8da5f7c030dc7
THREAD_SHA1_HASH_MOD_FUNC_OFFSET: 1362514c904581be6819c9ad457ddb0e0a348429
THREAD_SHA1_HASH_MOD: ef2aa043b63e07053dcc0140b8bae8887bda87e9
FAULT_INSTR_CODE: 10528b48
SYMBOL_STACK_INDEX: 0
SYMBOL_NAME: clr!JIT_IsInstanceOfClass2+1e
FOLLOWUP_NAME: MachineOwner
MODULE_NAME: clr
IMAGE_NAME: clr.dll
DEBUG_FLR_IMAGE_TIMESTAMP: 575a1507
STACK_COMMAND: ~6s ; kb
BUCKET_ID: INVALID_POINTER_READ_clr!JIT_IsInstanceOfClass2+1e
PRIMARY_PROBLEM_CLASS: INVALID_POINTER_READ_clr!JIT_IsInstanceOfClass2+1e
FAILURE_EXCEPTION_CODE: c0000005
FAILURE_IMAGE_NAME: clr.dll
BUCKET_ID_IMAGE_STR: clr.dll
FAILURE_MODULE_NAME: clr
BUCKET_ID_MODULE_STR: clr
FAILURE_FUNCTION_NAME: JIT_IsInstanceOfClass2
BUCKET_ID_FUNCTION_STR: JIT_IsInstanceOfClass2
BUCKET_ID_OFFSET: 1e
BUCKET_ID_MODPRIVATE: 1
BUCKET_ID_MODTIMEDATESTAMP: 575a1507
BUCKET_ID_MODCHECKSUM: 9e00c2
BUCKET_ID_MODVER_STR: 4.6.1586.0
BUCKET_ID_PREFIX_STR: INVALID_POINTER_READ_
FAILURE_PROBLEM_CLASS: INVALID_POINTER_READ
FAILURE_SYMBOL_NAME: clr.dll!JIT_IsInstanceOfClass2
FAILURE_BUCKET_ID: INVALID_POINTER_READ_c0000005_clr.dll!JIT_IsInstanceOfClass2
WATSON_STAGEONE_URL: http://watson.microsoft.com/StageOne/powershell.exe/10.0.14393.0/57899aad/clr.dll/4.6.1586.0/575a1507/c0000005/00003bae.htm?Retriage=1
TARGET_TIME: 2016-09-12T23:23:17.000Z
OSBUILD: 14393
OSSERVICEPACK: 0
SERVICEPACK_NUMBER: 0
OS_REVISION: 0
OSPLATFORM_TYPE: x64
OSNAME: Windows 10
OSEDITION: Windows 10 WinNt SingleUserTS
USER_LCID: 0
OSBUILD_TIMESTAMP: 2016-07-16 12:21:29
BUILDDATESTAMP_STR: 160715-1616
BUILDLAB_STR: rs1_release
BUILDOSVER_STR: 10.0.14393.0
ANALYSIS_SESSION_ELAPSED_TIME: 19ceb
ANALYSIS_SOURCE: UM
FAILURE_ID_HASH_STRING: um:invalid_pointer_read_c0000005_clr.dll!jit_isinstanceofclass2
FAILURE_ID_HASH: {8e51dedb-2c00-2e6e-4807-e20bf1dd21ab}
Followup: MachineOwner
---------
1:006> !clrstack
OS Thread Id: 0x3f50 (6)
Child SP IP Call Site
000000d242bfc4b8 00007ff85bea3bae [DebuggerU2MCatchHandlerFrame: 000000d242bfc4b8]
000000d242bfc7c8 00007ff85bea3bae [HelperMethodFrame_PROTECTOBJ: 000000d242bfc7c8] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
000000d242bfc940 00007ff859235230 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
000000d242bfc9b0 00007ff859234d32 System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
000000d242bfdaa0 00007ff85bea6a53 [DebuggerU2MCatchHandlerFrame: 000000d242bfdaa0]
000000d242bfdaf0 00007ff85bea6a53 [GCFrame: 000000d242bfdaf0]
000000d242bfdab8 00007ff85bea6a53 [GCFrame: 000000d242bfdab8]
1:006> .foreach (ex {!dumpheap -type Exception -short}){.echo "********************************";!pe ${ex} }
********************************
Exception object: 0000029c54761048
Exception type: System.Exception
Message: <none>
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80131500
********************************
Exception object: 0000029c547610e8
Exception type: System.OutOfMemoryException
Message: <none>
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 8007000e
********************************
Exception object: 0000029c54761188
Exception type: System.StackOverflowException
Message: <none>
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 800703e9
********************************
Exception object: 0000029c54761228
Exception type: System.ExecutionEngineException
Message: <none>
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80131506
********************************
Exception object: 0000029c547612c8
Exception type: System.Threading.ThreadAbortException
Message: <none>
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80131530
********************************
Exception object: 0000029c54761368
Exception type: System.Threading.ThreadAbortException
Message: <none>
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80131530
推荐答案
不确定这样做是否可以实现所需的功能,但是如果您只想等到导航完成,这是一个非常简单的解决方案:
Not sure if this accomplishes what you want, but it's a pretty simple solution if all you're hoping to do is wait until navigation is complete:
$ie = New-Object -com "InternetExplorer.Application"
$ie.Visible = $true # this may fail with "800706B5" ("The interface is unknown") if you aren't running PS as administrator
$ie.Navigate("https://www.google.com")
Do {sleep 1} While ($ie.Busy) #sometimes IE takes a second to get busy.
$ie.document.getelementbyid("q").value = "Powershell IE Automation"
$ie.document.getelementbyid("tsf").submit()
Do {sleep 1} While ($ie.Busy)
Do {sleep 1} While ($ie.Visible)
Write-Host "Done"
这篇关于PowerShell在NavigateComplete2事件触发时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!