VB Script für AutoIt umschreiben

  • Moin Community
    Ich habe volgendes VB Script

    Diese Script brauche Ich für AutoIt, könnte mir jemand Helfen es umzuschreiben?
    Habe leider keine Ahnung von VB

    Danke im vorraus

    mfg. Jam00

    • Offizieller Beitrag

    Hallo,

    so sollte es gehen:

    Spoiler anzeigen
    [autoit]

    ;~ Set Constants
    Const $NET_FW_IP_PROTOCOL_UDP = 17
    Const $NET_FW_IP_PROTOCOL_TCP = 6

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

    Const $NET_FW_SCOPE_ALL = 0
    Const $NET_FW_SCOPE_LOCAL_SUBNET = 1

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

    Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.

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

    $fwMgr = ObjCreate("HNetCfg.FwMgr")

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

    $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler

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

    $profile = $fwMgr.LocalPolicy.CurrentProfile

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

    If $g_eventerror then
    $g_eventerror = 0
    Msgbox (0,"COM Fehler","Fehlernummer: " & @error)
    Exit
    Endif

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

    $port = ObjCreate("HNetCfg.FWOpenPort")

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

    $port.Name = "HTTP"
    $port.Protocol = $NET_FW_IP_PROTOCOL_TCP
    $port.Port = 80

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

    ;~ If using Scope, don't use RemoteAddresses
    $port.Scope = $NET_FW_SCOPE_ALL
    ;~ Use this line to scope the port to Local Subnet only
    ;~ $port.Scope = $NET_FW_SCOPE_LOCAL_SUBNET

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

    $port.Enabled = TRUE
    ;~ Use this line instead if you want to add the port, but disabled
    ;~ $port.Enabled = FALSE

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

    $profile.GloballyOpenPorts.Add($port)

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

    If $g_eventerror then
    $g_eventerror = 0
    Msgbox (0,"COM Fehler","Fehlernummer: " & @error)
    Exit
    Endif

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

    ; This is my custom defined error handler
    Func MyErrFunc()

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

    Msgbox(0,"COM-Error","We intercepted a COM Error !" & @CRLF & @CRLF & _
    "err.description is: " & @TAB & $oMyError.description & @CRLF & _
    "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
    "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _
    "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
    "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
    "err.source is: " & @TAB & $oMyError.source & @CRLF & _
    "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
    "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
    )

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

    Local $err = $oMyError.number
    If $err = 0 Then $err = -1

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

    $g_eventerror = $err ; to check for after this function returns
    Endfunc

    [/autoit]
  • Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    ;Set Constants
    Global Const $NET_FW_IP_PROTOCOL_UDP = 17
    Global Const $NET_FW_IP_PROTOCOL_TCP = 6

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

    Global Const $NET_FW_SCOPE_ALL = 0
    Global Const $NET_FW_SCOPE_LOCAL_SUBNET = 1

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

    ;Declare variables
    Dim $errornum

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

    ;Create the firewall manager object.
    Dim $fwMgr
    $fwMgr = ObjCreate("HNetCfg.FwMgr")
    if @error Then
    ConsoleWrite("Objekt HNetCfg.FwMgr konnte nicht erstellt werden" & @CRLF)
    Exit
    endif

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

    ; Get the current profile for the local firewall policy.
    Dim $profile
    $profile = $fwMgr.LocalPolicy.CurrentProfile

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

    Dim $port
    $port = Objcreate("HNetCfg.FWOpenPort")
    if @error Then
    ConsoleWrite("Objekt HNetCfg.FWOpenPort konnte nicht erstellt werden" & @CRLF)
    Exit
    endif

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

    $port.Name ='HTTP'
    $port.Protocol =6
    $port.Port =80

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

    ;If using Scope, don't use RemoteAddresses
    $port.Scope =$NET_FW_SCOPE_ALL
    ;Use this line to scope the port to Local Subnet only
    ;port.Scope = NET_FW_SCOPE_LOCAL_SUBNET

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

    $port.Enabled=TRUE
    ;Use this line instead if you want to add the port, but disabled
    ;port.Enabled = FALSE

    [/autoit]


    So ca. (ohne Error-Handling edit \ -> s. Bernd's Antwort)

  • Hier nochma für Programme

    Spoiler anzeigen
    [autoit]

    ;~ ' Set constants
    Const $NET_FW_PROFILE_DOMAIN = 0
    Const $NET_FW_PROFILE_STANDARD = 1

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

    ;~ ' Scope
    Const $NET_FW_SCOPE_ALL = 0

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

    ;~ ' IP Version <entity type="ndash"/> ANY is the only allowable setting for now
    Const $NET_FW_IP_VERSION_ANY = 2

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

    ;~ ' Declare variables
    Dim $errornum

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

    ;~ ' Create the firewall manager object.
    Dim $fwMgr
    $fwMgr = ObjCreate("HNetCfg.FwMgr")

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

    ;~ ' Get the current profile for the local firewall policy.
    Dim $profile
    $profile = $fwMgr.LocalPolicy.CurrentProfile

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

    Dim $app
    $app = ObjCreate("HNetCfg.FwAuthorizedApplication")

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

    $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler

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

    $app.ProcessImageFileName = "%PROGRAMFILES%\Outlook Express\msimn.exe"
    $app.Name = "Outlook Express"
    $app.Scope = $NET_FW_SCOPE_ALL
    ;~ ' Use either Scope or RemoteAddresses, but not both
    ;~ 'app.RemoteAddresses = "*"
    $app.IpVersion = $NET_FW_IP_VERSION_ANY
    $app.Enabled = TRUE

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

    ;~ ' Use this line if you want to add the app, but disabled.
    ;~ 'app.Enabled = FALSE

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

    ;~ $errornum = 0
    $profile.AuthorizedApplications.Add($app)
    ;~ $errornum = Err.Number
    ;~ if $errornum <> 0 then MsgBox(0,"","Adding authorized application failed with: " & $errornum)

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

    ; This is my custom defined error handler
    Func MyErrFunc()

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

    Msgbox(0,"COM-Error","We intercepted a COM Error !" & @CRLF & @CRLF & _
    "err.description is: " & @TAB & $oMyError.description & @CRLF & _
    "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
    "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _
    "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
    "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
    "err.source is: " & @TAB & $oMyError.source & @CRLF & _
    "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
    "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
    )

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

    Local $err = $oMyError.number
    If $err = 0 Then $err = -1

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

    $g_eventerror = $err ; to check for after this function returns
    Endfunc

    [/autoit]

    Da sieht du es auch bei Ausnahmen das er es hinzugefügt hat.