MSScriptControl.ScriptControl in Autoitscript einbinden

  • [autoit]

    $SC = ObjCreate("MSScriptControl.ScriptControl")
    if IsObj($SC) Then
    $SC.Language = "VBScript"
    Else
    _log("Error","Scriptcontrole Objekt konnte nicht initialisiert werden")
    EndIf

    [/autoit]

    um mit

    $sc.addcode($code)

    dann den VBscriptcode ausführen zu lassen.

    Für Lösungsvorschläge bin ich dankbar

    P.S. $SC = ObjCreate('ScriptControl') habe ich schon versucht geht leider nicht. :(

  • fehlt da nicht irgendwie

    [autoit]

    GuiCtrlCreateObj

    [/autoit]

    Wiso meinst du das?? ist doch kein Gui Element alles was ich mache hat nicht uns soll auch nichts mit einer Gui zu tun haben.

    Laut Anleitungen im Inet soll das so gehen:

    Spoiler anzeigen
    [autoit]

    Global $Vbs, $sCode, $sRET

    [/autoit] [autoit][/autoit] [autoit]

    $sCode = 'Function RegexMatches(sPattern, sString)' & _
    @LF & ' Dim oRegEx, oMatch, oMatches, RetStr' & _ ; Create variables.
    @LF & ' Set oRegEx = New RegExp' & _ ; Create regular expression.
    @LF & ' oRegEx.Pattern = sPattern' & _ ; Set pattern.
    @LF & ' oRegEx.IgnoreCase = True' & _ ; Set case sensitivity.
    @LF & ' oRegEx.Global = True' & _ ; Set Global option.
    @LF & ' Set oMatches = oRegEx.Execute(sString)' & _ ; Execute the search test.
    @LF & ' For Each oMatch in oMatches' & _
    @LF & ' RetStr = RetStr & "Match found at position "' & _
    @LF & ' RetStr = RetStr & oMatch.FirstIndex & vbCRLF' & _
    @LF & ' RetStr = RetStr & "Match Value is "' & _
    @LF & ' RetStr = RetStr & oMatch.Value & "." & vbCRLF & vbCRLF' & _
    @LF & ' Next' & _
    @LF & ' RegexMatches = RetStr' & _
    @LF & 'End Function' & _
    @LF

    [/autoit] [autoit][/autoit] [autoit]

    $Vbs = ObjCreate('ScriptControl')
    If @error Then
    MsgBox(16, 'Error', 'Error creating MSScriptControl.ScriptControl')
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $Vbs.Language = 'VBScript'

    [/autoit] [autoit][/autoit] [autoit]

    $Vbs.AddCode($sCode)

    [/autoit] [autoit][/autoit] [autoit]

    $sRET = $Vbs.Run('RegexMatches', '\d+', 'ABC123DEF')
    Funktioniert bei mir Aber nicht.

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite("$sRET = " & $sRET & @LF)

    [/autoit]
  • Funktioniert doch!

    Hier noch mal in einer Funktion:

    Spoiler anzeigen
    [autoit]

    ConsoleWrite(_RegexMatches('\d+', 'ABC123DEF') & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    Func _RegexMatches($sPattern, $sString)
    Local $sCode = 'Function RegexMatches(sPattern, sString)' & _
    @LF & ' Dim oRegEx, oMatch, oMatches, RetStr' & _ ; Create variables.
    @LF & ' Set oRegEx = New RegExp' & _ ; Create regular expression.
    @LF & ' oRegEx.Pattern = sPattern' & _ ; Set pattern.
    @LF & ' oRegEx.IgnoreCase = True' & _ ; Set case sensitivity.
    @LF & ' oRegEx.Global = True' & _ ; Set Global option.
    @LF & ' Set oMatches = oRegEx.Execute(sString)' & _ ; Execute the search test.
    @LF & ' For Each oMatch in oMatches' & _
    @LF & ' RetStr = RetStr & "Match found at position "' & _
    @LF & ' RetStr = RetStr & oMatch.FirstIndex & vbCRLF' & _
    @LF & ' RetStr = RetStr & "Match Value is "' & _
    @LF & ' RetStr = RetStr & oMatch.Value & "." & vbCRLF & vbCRLF' & _
    @LF & ' Next' & _
    @LF & ' RegexMatches = RetStr' & _
    @LF & 'End Function' & @LF
    Local $Vbs = ObjCreate('ScriptControl')
    $Vbs.Language = 'VBScript'
    $Vbs.AddCode($sCode)
    $sRET = $Vbs.Run('RegexMatches', $sPattern, $sString)
    Return $sRet
    EndFunc

    [/autoit]
  • Hm... meine Fehlermeldung:

    Spoiler anzeigen

    >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Rollout\Desktop\wsctest.au3" /autoit3dir "C:\Program Files (x86)\AutoIt3" /UserParams
    +>10:06:07 Starting AutoIt3Wrapper v.2.0.0.1 Environment(Language:0409 Keyboard:00000407 OS:WIN_2008/Service Pack 2 CPU:X64 OS:X64)
    >Running AU3Check (1.54.14.0) from:C:\Program Files (x86)\AutoIt3
    +>10:06:07 AU3Check ended.rc:0
    >Running:(3.3.0.0):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\Rollout\Desktop\wsctest.au3"
    C:\Users\Rollout\Desktop\wsctest.au3 (20) : ==> Variable must be of type "Object".:
    $Vbs.Language = 'VBScript'
    $Vbs^ ERROR
    ->10:06:07 AutoIT3.exe ended.rc:1
    +>10:06:08 AutoIt3Wrapper Finished
    >Exit code: 1 Time: 1.346

  • Hi,

    Du lässt ein 32 Bit auf 64 Bit laufen.

    s. helpfile AutoIT

    Zitat

    Running under Windows 64-bit Edition
    AutoIt has traditionally been a 32-bit application. With the 3.2.10.0 release native x64 versions of some components have been added, including:

    AutoIt (AutoIt3_x64.exe)
    Aut2Exe (Aut2Exe_x64.exe)
    Au3Info (Au3Info_x64.exe)
    AutoItX (AutoItX3_x64.dll)
    During installation, if found to be running on x64 you will be given the choice to install and configure the x64 versions. These versions are fully x64 compatible, however, some scripts that use DllCall/DllStruct with custom structures may use values that break 64-bit compatibility (such as using 32-bit integers for pointers). This includes some of the UDFs supplied with AutoIt as they have not all been tested under x64.

    You can run the x86 version of AutoIt by right-clicking a script and selecting "Run Script (x86)".

    If you suspect that a script is not working correctly under x64 but it works under x86 then please report a bug.

    To see if you are running under a 64-Bit Edition of Windows use @OSArch macro. To see if you are using the 32 or 64-bit version of AutoIt use @AutoItX64.

    ;-))
    Stefan

    P.S: Bei mir auf 32 Bit XP Sp3 ohne Probleme