Seahorse Posted May 19, 2010 Posted May 19, 2010 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 Seahorsescript.au3
water Posted May 19, 2010 Posted May 19, 2010 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 2024-07-28 - Version 1.6.3.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 (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
Seahorse Posted May 20, 2010 Author Posted May 20, 2010 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
water Posted May 20, 2010 Posted May 20, 2010 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 2024-07-28 - Version 1.6.3.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 (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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now