Jump to content

Error parsing function call


Recommended Posts

I am receieving the following error with my script after converting to au3.

Error parsing function call

My intension is to convert into EXE but receive the error.

The script works ok when executed as vbs with its original coding but after being converted it no longer works.

I have uploaded the file for your perusal and would greatly appreciate any help you can provide.

My experience with scripting is very basic but I have a number of scripts in use to make my life easier which I would like to share with colleagues as EXE.

I am currently attempting to better my scripting skills and would like to begin using AutoIt as an alternative to vbs.

Thank you

Kind Regards

Seahorse

script.au3

Link to comment
Share on other sites

Something like this?

$WshShell = ObjCreate("WScript.Shell")

Global $nAble = 0
$aGateway = StringSplit(DefaultGateway(), ".")
Select
    Case $aGateway[0] = "172"
        $nAble = 1
    Case $aGateway[0] = "192"
        $nAble = 0
    Case Else
        $nAble = 0
EndSelect
$WshShell.RegWrite("HKCU\software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", $nAble, "REG_DWORD")
$WshShell.RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", $nAble, "REG_DWORD")

Func DefaultGateway()
    Local $Return = "", $oDG, $oDGs, $WMI
    $WMI = ObjGet("winmgmts:\\.\root\cimv2")
    $oDGs = $WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=" & True)
    For $oDG In $oDGs
        If $oDG.defaultIPGateway(0) <> "0.0.0.0" Then
            $Return = $oDG.DefaultIPGateway(0)
            ExitLoop
        EndIf
    Next
    Return $Return
EndFunc ;==>DefaultGateway

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you

It does appear to be working without error.

Unfortunately it is performing the oposite function to what I'd like it to.

Case $aGateway[0] = "172"

$nAble = 1

Case $aGateway[0] = "192"

$nAble = 0

Case Else

$nAble = 0

To me this looks fine but I'm sure I'm missing something.

I have changed it to remove the "192" and left Case Else to disable instead.

This has made no difference. I'm wondering whether the script is skipping the detection of the default gateway and simply blanking the registry DWORD.

Could the ordering be out slightly?

Thank you

Link to comment
Share on other sites

Insert some ConsoleWrite statements so you can see what's going on:

$WshShell = ObjCreate("WScript.Shell")

Global $nAble = 0
$Result = DefaultGateway()
$aGateway = StringSplit($Result, ".")
ConsoleWrite("Gateway: " & $Result & @CRLF)
ConsoleWrite("Gateway[0]: " & $aGateway[0] & @CRLF)
Select
    Case $aGateway[0] = "172"
    $nAble = 1
    Case $aGateway[0] = "192"
    $nAble = 0
    Case Else
    $nAble = 0
EndSelect
ConsoleWrite("$nAble: " & $nAble & @CRLF)
$WshShell.RegWrite("HKCU\software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", $nAble, "REG_DWORD")
$WshShell.RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", $nAble, "REG_DWORD")

Func DefaultGateway()
    Local $Return = "", $oDG, $oDGs, $WMI
    $WMI = ObjGet("winmgmts:\\.\root\cimv2")
    $oDGs = $WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=" & True)
    For $oDG In $oDGs
    If $oDG.defaultIPGateway(0) <> "0.0.0.0" Then
    $Return = $oDG.DefaultIPGateway(0)
    ExitLoop
    EndIf
    Next
    Return $Return
EndFunc ;==>DefaultGateway

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...