Sign in to follow this  
Followers 0
Seahorse

Error parsing function call

5 posts in this topic

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank you

I'll give it a go and report back.

Share this post


Link to post
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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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
Sign in to follow this  
Followers 0