Jump to content

Recommended Posts

j0kky

Hi guys,

I'm trying to use the Open Hardware Monitor library to read some values about the hardware. I know that I could run directly OpenHardwareMonitor.exe and read from WMI but I want to use the library.

It is written in C# but I've read from >this topic I can use RegAsm to register the types in the registry so I could run the classes in the library as COM objects.

I've downloaded the source, changed COMVISIBLE property to TRUE and compiled the library with MSBuild.exe

I would convert this (or this) script to Autoit but after some lines of code I get an error: "Invalid pointer".

I don't understand why I get that error, I don't think it's cause RegAsm because it gives me a warning but then it does its job registering the types.

#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 

I'll attach the compiled dll but you need to check .NET Framework folder first.

Thank you at all.

Edited by j0kky

Share this post


Link to post
Share on other sites
mLipok

Add msgbox after $CP.Open

Edit: and say what you notice

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-15

Share this post


Link to post
Share on other sites
j0kky

nothing, nothing can happen... COM error handling function contains an "exit" statement and the script ends before executing everything after $cp.Open (that generates the COM error)

Share this post


Link to post
Share on other sites
mLipok

;~ $cp = ObjCreate("OpenHardwareMonitor.Hardware.Computer")
$cp = ObjCreate("OpenHardwareMonitorLib")


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-15

Share this post


Link to post
Share on other sites
j0kky

"Invalid Class String" COM error.

In fact this is what RegAsm adds to the registry: 

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"

And I've attached an image of what OLEView shows.

post-74111-0-02347200-1404134953_thumb.j

Share this post


Link to post
Share on other sites
j0kky

New issue :) thanks to this patch I could write a new version of OpenHardwareMonitorLib.dll, now I can run my script without errors, till I try to enumerate a collection: then Autoit crashes without errors.
It seems to be an Autoit managing-object related issue and not an external library issue, I'll attach the new version of the library.
Have you got any idea?

#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)
Sleep(1000)

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$cp = ObjCreate("OpenHardwareMonitor.Hardware.Computer")
If IsObj($cp) Then
    MsgBox(0, "OpenHardwareMonitor.Hardware.Computer", "Object created")
    $cp.Open()
    $cp.GPUEnabled = True
    $cp.CPUEnabled = True
    $a = $cp.Hardware
    MsgBox(0,"Var type",VarGetType($a))

    For $HWItem In $a ;---------> error
        MsgBox(0, 1, "hello")
    Next
Else
    MsgBox(16, "ERROR", "Object not created")
EndIf


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   ;==>MyErrFunc

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   ;==>_Read_Std

P.S: extract the dll in the same directory of the script and check your .NET Framework version  :bye:

EDIT:

I adjusted the code formatting

OpenHardwareMonitorLib.zip

Edited by j0kky

Share this post


Link to post
Share on other sites
water

We need more information to track down the error:

Which version of AutoIt?

What's the result of VarGetType($a)?

Do you get any messages from the COM error handler?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
j0kky

Autoit v3.3.12.0

VarGetType($a) = "Object"

No error from internal COM error handler, it is an hard crash ("Autoit v3 script has stopped working" in english):

post-74111-0-24725900-1425117715_thumb.j

Useless crash data:

Descrizione:
  Stopped working

Firma problema:
  Nome evento problema: APPCRASH
  Application Name: autoit3.exe
  Application Version:  3.3.12.0
  Application Timestamp:    538b6694
  Fault Module Name:    autoit3.exe
  Fault Module Version: 3.3.12.0
  Fault Module Timestamp:   538b6694
  Exception Code:   c0000005
  Exception Offset: 0005bb71
  Versione SO:  6.1.7601.2.1.0.768.3
  ID impostazioni locali:   1040

Share this post


Link to post
Share on other sites
water

The history for the latest AutoIt beta version doesn't list fixes for COM problems so I fear installing the latest beta won't help.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

If $a.count returns a value you could loop through the collection like an array. Maybe this works.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
j0kky

Count method is not exported by the library and the COM error handler reports a NULL pointer error if I try to do $a.Count.

This is what ILSpy shows about method and properties exported with Computer Class (on the left) and the source code of Hardware method (on the right):

post-74111-0-57527400-1425122759_thumb.j

Share this post


Link to post
Share on other sites
j0kky

"Business reading"? Ehm... what?

EDIT:

I tried something about c0000005: http://stackoverflow.com/a/17169463/3812399

But it doesn't really help until I will inspect $a to see if it is empty or something else.

Edited by j0kky

Share this post


Link to post
Share on other sites
j0kky

Just a clarification, the library works without problems if I don't try to enumerate that collection, for example if you run this script it works:

#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)
Sleep(1000)

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$cp = ObjCreate("OpenHardwareMonitor.Hardware.Computer")
If IsObj($cp) Then
    MsgBox(0, "OpenHardwareMonitor.Hardware.Computer", "Object created")
    $cp.Open()
    $cp.GPUEnabled = True
    $cp.CPUEnabled = True
    $a = $cp.Hardware
    MsgBox(0,"Var type",VarGetType($a))
    FileWrite(@DesktopDir & "\log.txt", $cp.GetReport)

Else
    MsgBox(16, "ERROR", "Object not created")
EndIf


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   ;==>MyErrFunc

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   ;==>_Read_Std

But GetReport method returns a string, not an array as .Hardware method.

Is there any way to look into $a (other else than Count)?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • genius257
      By genius257
      I've made a library, based on AutoItObject UDF with the goal of implementing getter and setter functionality and make it possible to define new object properties in as few steps as possible.
      Thank you to @trancexx for getting me on the right track, and all users in Hooking into the IDispatch interface for the code to get me going.
      If I've forgotten to add credit, please let me know
      Example:
      #include "AutoItObject_Internal.au3" $myCar = IDispatch() $myCar.make = 'Ford' $myCar.model = 'Mustang' $myCar.year = 1969 $myCar.__defineGetter('DisplayCar', DisplayCar) Func DisplayCar($oThis) Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model EndFunc MsgBox(0, "", $myCar.DisplayCar) More examples: https://github.com/genius257/AutoItObject-Internal/tree/master/Examples
      Version: 2.0.0
      AutoItObject_Internal.au3
      Documentation
      Edit2 (19th March 2017):
      First of all, sorry about the lack of updates on this project. I always start too many projects and end up ignoring old projects, if I run into problems ^^'.
      So I've started moving my AutoIt scripts to GitHub. I will still post the most recent script version here.
    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
    • tuffgong
      By tuffgong
      Good morning. I have a system I am trying to automate that works like this: user fills a column in an Excel spreadsheet with values they would like printed and saves it to a folder on their desktop, they start the script and it formats their data into a text file (adding a prefix) and sends the text file as a .bch file where it needs to go. This is working:
      #include <Array.au3> #include <Excel.au3> #include <File.au3> #include <MsgBoxConstants.au3> Global $sSTCArray Global $sFilename = @DesktopDir & "\Labels\print.txt" Global $sWorkbook = @DesktopDir & "\Labels\Labels.xlsx" Global $oExcel = _Excel_Open(False,False,False,False,True) barcodePrint() Func barcodePrint() $Read = _Excel_BookOpen($oExcel, $sWorkbook, True, False, Default, Default, Default) FileOpen($sFilename, $FO_OVERWRITE) ;Global $oWorkbook = _Excel_BookAttach($oExcel) Global $sSTCArray = _Excel_RangeRead($Read) For $i = 0 to UBound($sSTCArray, 1) - 1 FileWriteLine($sFilename, "!StaticShelving1x3_ZPL," & $sSTCArray[$i]) Next _Excel_Close($oExcel) FileMove($sFilename, "***file path***\print.bch") EndFunc However, it only works if the user first formats the spreadsheet to text. I want to automate that. From what I have read it appears AutoIt does not like formatting cells that already have values. True? Can I pull the values from an un-formatted (default GENERAL format) spreadsheet and go straight to my text file? I have also considered opening a second spreadsheet, formatting it, and copying the values over. Like this:
        
      Global $sPrefix Global $oPath Global $sSTCArray Global $sFilename = @DesktopDir & "\Labels\print.txt" Global $sWorkbook = @DesktopDir & "\Labels\Labels.xlsx" Global $oExcel = _Excel_Open(False,False,False,False,True) Global $aArray Global $bExcel _Excel_BookNew($bExcel) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $aArray = IniReadSection("***File path***\barcode.ini", "stc/rvt/mgm") $sPrefix = $aArray[1][1] $oPath = $aArray[2][1] barcodePrint() EndSwitch WEnd Func barcodePrint() $oWorkbook = _Excel_BookOpen($bExcel, @DesktopDir & "\Labels\print.xlsx") $oWorkbook.ActiveSheet.Columns("A").NumberFormat = "@" Local $Read = _Excel_BookOpen($oExcel, $sWorkbook, True, False, Default, Default, Default) $oCopy = _Excel_RangeRead($sWorkbook) _Excel_RangeWrite($oWorkbook, Default, $oCopy) FileOpen($sFilename, $FO_OVERWRITE) $sSTCArray = _Excel_RangeRead($Read,"Default","Default",3) ;_ArrayDisplay($sSTCArray) For $i = 0 to UBound($sSTCArray, 1) - 1 FileWriteLine($sFilename, $sPrefix & $sSTCArray[$i]) Next _Excel_Close($oExcel) ;FileMove($sFilename, $oPath) Exit EndFunc This does not like the formatting of $oWorkbook: "Variable must be of type 'Object'".  Do I need this second sheet? If so, how can I format it? Is there a better way to get the Excel values into a .txt file? Any ideas would be appreciated. Thanks!
    • marcoauto
      By marcoauto
      Ciao
      I would like to control an ATEM Video Mixer from autoit. I downloaded his SDK which is written in c ++ and I found the sequences to interface, but I was not able to convert the script to self.
      The instructions say to follow this sequence:
      and to connectTo with C++ is:
      string address = "192.168.1.240"; _BMDSwitcherConnectToFailure failureReason = 0; IBMDSwitcher switcher = null; var discovery = new CBMDSwitcherDiscovery(); discovery.ConnectTo(address, out switcher, out failureReason); From Blackmagic SDK:
      IBMDSwitcherDiscovery::ConnectTo method
      The ConnectTo method connects to the specified switcher and returns an IBMDSwitcher object interface for the switcher.
      Syntax HRESULT ConnectTo (string deviceAddress, IBMDSwitcher** switcherDevice, BMDSwitcherConnectToFailure* failReason); Parameters: deviceAddress in Network hostname or IP address of switcher to connect to. switcherDevice out IBMDSwitcher object interface for the connected switcher. failReason out Reason for connection failure as a BMDSwitcherConnectToFailure value. So, I have I tried these solutions but with non success:
      $DllName =@ScriptDir&"\BMDSwitcherAPI.dll" $result = DllCall($DllName, "none", "IBMDSwitcherDiscovery::ConnectTo" & @CRLF) ConsoleWrite("DLLCall Result: " & $result & @CRLF) and I have tried also create an Object (That I think is the best way solution):
      #include <MsgBoxConstants.au3> $oSwitcher=ObjCreate("IBMDSwitcher") If IsObj($oSwitcher) Then MsgBox(64, "", "Object $oSwitcher created successfully") EndIf $oAtem=ObjCreate("IBMDSwitcherDiscovery") If IsObj($oAtem) Then MsgBox(64, "", "Object $oAtem created successfully") EndIf $failureReason =ObjCreate("_BMDSwitcherConnectToFailure") If IsObj($failureReason) Then MsgBox(64, "", "Object $failureReason created successfully") EndIf $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler Global $errore,$oSwitcher1 $oAtem.ConnectTo("192.168.1.36",$oSwitcher,$failureReason); ; This is the custom error handler 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 & _ "Helpfile is: " & $oMyError.helpfile & @CRLF & _ "Helpcontext is: " & $oMyError.helpcontext & @CRLF & _ "Lastdllerror is: " & $oMyError.lastdllerror & @CRLF & _ "Scriptline is: " & $oMyError.scriptline) EndFunc ;==>MyErrFunc But the result is:
      We intercepted a COM Error !
      Number is: 000000A9
      Windescription is: Variable must be of type 'Object'.
      Source is: 
      Description is: 
      Helpfile is: 
      Helpcontext is: 
      Lastdllerror is: 0
      Scriptline is: 17
      The BMDSwitcherAPI.dll is registered in system. Can someone help me?
      Grazie
      Marco
    • Bilgus
      By Bilgus
      ; NetFirewallPolicy2 COM UDF Library for AutoIt3
      ; AutoIt Version : 3.3.14.5
      ; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+
      Including Test Script 
      _NetFw_Get_CurrentProfileTypes                           Retrieves the currently active firewall profile(s) _NetFw_Get_FirewallEnabled                               Indicates whether a firewall is enabled locally _NetFw_Put_FirewallEnabled                               Specifies whether a firewall is enabled locally _NetFw_Get_ExcludedInterfaces                            Indicates a list of interfaces on which firewall settings are excluded _NetFw_Put_ExcludedInterfaces                            Specifies a list of interfaces on which firewall settings are excluded _NetFw_Get_BlockAllInboundTraffic                        Indicates whether the firewall should not allow inbound traffic _NetFw_Put_BlockAllInboundTraffic                        Specifies whether the firewall should not allow inbound traffic _NetFw_Get_NotificationsDisabled                         Indicates whether interactive firewall notifications are disabled _NetFw_Put_NotificationsDisabled                         Specifies whether interactive firewall notifications are disabled _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled  Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled  Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Get_Rules                                         Retrieves the interface to collection of firewall rules _NetFw_Get_ServiceRestriction                            Retrieves the interface used to access the Windows Service Hardening store _NetFw_EnableRuleGroup                                   Enables or disables a specified group of firewall rules _NetFw_IsRuleGroupEnabled                                Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_RestoreLocalFirewallDefaults                      Restores the local firewall configuration to its default state _NetFw_Get_DefaultInboundAction                          Indicates the default action for inbound traffic _NetFw_Put_DefaultInboundAction                          Specifies the default action for inbound traffic _NetFw_Get_DefaultOutboundAction                         Indicates the default action for outbound traffic _NetFw_Put_DefaultOutboundAction                         Specifies the default action for outbound traffic _NetFw_Get_IsRuleGroupCurrentlyEnabled                   Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_Get_LocalPolicyModifyState                        Determines if adding or setting a rule or group of rules will take effect in the current firewall profile  
      UDF:
      Test Script:
       
×