我会使用Open Hardware Monitor库来读取有关硬件的一些值,而不是执行OpenHardwareMonitor.exe并从WMI读取,所以我使用RegAsm在注册表中注册类型(所以我可以在库中运行类)作为COM对象)。 首先,我已将项目的COMVISIBLE属性更改为TRUE,并且我已使用MSBuild.exe重新编译了库。 我会将this脚本转换为Autoit但是当我尝试调用任何方法时,我收到错误:"指针无效"。或"异常:对象引用未设置为对象的实例"。 我不明白为什么我会收到这个错误,我不认为它导致RegAsm,因为它给了我一个警告,但它确实记录了它的类型,这就是它增加了注册表:
REGEDIT4
[HKEY_CLASSES_ROOT\Record\{1FD2DBF2-D8C3-3E57-B448-37196EB12D9C}\0.6.0.11]
"Class"="OpenHardwareMonitor.Hardware.ControlMode"
"Assembly"="OpenHardwareMonitorLib, Version=0.6.0.11, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="file:///C:/Users/gianluca/Desktop/lavoro/openhardwaremonitorlib.dll"
[HKEY_CLASSES_ROOT\OpenHardwareMonitor.Hardware.Computer]
@="OpenHardwareMonitor.Hardware.Computer"
[HKEY_CLASSES_ROOT\OpenHardwareMonitor.Hardware.Computer\CLSID]
@="{5E652471-D269-3567-BB38-DCEBFF5669CF}"
[HKEY_CLASSES_ROOT\CLSID\{5E652471-D269-3567-BB38-DCEBFF5669CF}]
@="OpenHardwareMonitor.Hardware.Computer"
[HKEY_CLASSES_ROOT\CLSID\{5E652471-D269-3567-BB38-DCEBFF5669CF}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="OpenHardwareMonitor.Hardware.Computer"
"Assembly"="OpenHardwareMonitorLib, Version=0.6.0.11, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="file:///C:/Users/gianluca/Desktop/lavoro/openhardwaremonitorlib.dll"
[HKEY_CLASSES_ROOT\CLSID\{5E652471-D269-3567-BB38-DCEBFF5669CF}\InprocServer32\0.6.0.11]
"Class"="OpenHardwareMonitor.Hardware.Computer"
"Assembly"="OpenHardwareMonitorLib, Version=0.6.0.11, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="file:///C:/Users/gianluca/Desktop/lavoro/openhardwaremonitorlib.dll"
[HKEY_CLASSES_ROOT\CLSID\{5E652471-D269-3567-BB38-DCEBFF5669CF}\ProgId]
@="OpenHardwareMonitor.Hardware.Computer"
[HKEY_CLASSES_ROOT\CLSID\{5E652471-D269-3567-BB38-DCEBFF5669CF}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]
[HKEY_CLASSES_ROOT\Record\{E4E64F96-C708-381E-8380-93DF59B324B0}\0.6.0.11]
"Class"="OpenHardwareMonitor.Hardware.HardwareType"
"Assembly"="OpenHardwareMonitorLib, Version=0.6.0.11, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="file:///C:/Users/gianluca/Desktop/lavoro/openhardwaremonitorlib.dll"
[HKEY_CLASSES_ROOT\Record\{DFC56287-93E1-3B82-8F95-5F4268CB0401}\0.6.0.11]
"Class"="OpenHardwareMonitor.Hardware.SensorType"
"Assembly"="OpenHardwareMonitorLib, Version=0.6.0.11, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="file:///C:/Users/gianluca/Desktop/lavoro/openhardwaremonitorlib.dll"
[HKEY_CLASSES_ROOT\Record\{6042D116-95C1-3C8A-B8DC-D0E6C8F5BA07}\0.6.0.11]
"Class"="OpenHardwareMonitor.Hardware.SensorValue"
"Assembly"="OpenHardwareMonitorLib, Version=0.6.0.11, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="file:///C:/Users/gianluca/Desktop/lavoro/openhardwaremonitorlib.dll"
这是OLEView显示的内容:http://i.stack.imgur.com/Oa1NO.jpg 这是生成错误的简单脚本:
#RequireAdmin
$RegAsm_path = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm" ; CHECK YOUR VERSION!!!
$foo = Run($RegAsm_path & " /codebase /nologo OpenHardwareMonitorlib.dll", "", @SW_HIDE, 0x2 + 0x4)
$std = _Read_Std($foo)
MsgBox(0,$foo,$std)
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
$cp = ObjCreate("OpenHardwareMonitor.Hardware.Computer")
If IsObj($cp) Then MsgBox(0,"OpenHardwareMonitor.Hardware.Computer","Object created")
$cp.Open() ; <--------------- ERROR
RunWait($RegAsm_path & " /nologo /unregister OpenHardwareMonitorlib.dll", "", @SW_HIDE)
Func MyErrFunc()
$HexNumber=hex($oMyError.number,8)
Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
"Number is: " & $HexNumber & @CRLF & _
"Windescription is: " & $oMyError.windescription & @CRLF & _
"Source is: " & $oMyError.source & @CRLF & _
"Description is: " & $oMyError.description & @CRLF & _
"Script line is: " & $oMyError.scriptline)
RunWait($RegAsm_path & " /nologo /unregister OpenHardwareMonitorlib.dll", "", @SW_HIDE)
Exit
Endfunc
Func _Read_Std($handle)
Local $s
While 1
$s &= StdoutRead($handle)
If @error Then ExitLoop
$s &= StderrRead($handle)
If @error Then ExitLoop
WEnd
Return $s
EndFunc
首先执行脚本,您需要在第二行检查.NET Framework版本。 This是包含脚本和库
的存档答案 0 :(得分:0)
您是否尝试将#AutoIt3Wrapper_UseX64 = N添加到脚本中以将其作为32位COM对象运行