Jump to content

Recommended Posts

Posted

OK. The script works fine by itself.

But, when I add it to my GUI script, I now get errors.

What I am trying to do is, in the GUI, run a function when a button is pressed- like this one:

; END

Func ping1Pressed()

RunWait(@COMSPEC & " /c ping 127.0.0.1 & pause")

EndFunc

-----

When I just add your script in place of the line: "RunWait(@COMSPEC & " /c ping 127.0.0.1 & pause")", I get the following errors:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /prod /AU3Check /in "I:\Feb 2008\In Work\My GUI\My GUI.au3"

+>17:18:07 Starting AutoIt3Wrapper v.1.9.5.6 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X86)

>Running AU3Check (1.54.10.0) from:C:\Program Files\AutoIt3

I:\Feb 2008\In Work\My GUI\My GUI.au3(150,1) : ERROR: syntax error

Func

^

I:\Feb 2008\In Work\My GUI\My GUI.au3(8,48) : ERROR: SpecialEvents(): undefined function.

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I:\Feb 2008\In Work\My GUI\My GUI.au3(40,37) : ERROR: Ping3Pressed(): undefined function.

GUICtrlSetOnEvent(-1, "Ping3Pressed")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I:\Feb 2008\In Work\My GUI\My GUI.au3(43,37) : ERROR: Ping4Pressed(): undefined function.

GUICtrlSetOnEvent(-1, "Ping4Pressed")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I:\Feb 2008\In Work\My GUI\My GUI.au3(46,37) : ERROR: Ping5Pressed(): undefined function.

GUICtrlSetOnEvent(-1, "Ping5Pressed")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I:\Feb 2008\In Work\My GUI\My GUI.au3(49,37) : ERROR: Ping6Pressed(): undefined function.

GUICtrlSetOnEvent(-1, "Ping6Pressed")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I:\Feb 2008\In Work\My GUI\My GUI.au3(134,45) : ERROR: _RunStdOutRead(): undefined function.

$IP_Address = _RunStdOutRead('IPConfig /ALL')

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I:\Feb 2008\In Work\My GUI\My GUI.au3 - 7 error(s), 0 warning(s)

!>17:18:08 AU3Check ended.rc:2

------

I get no errors until I add your script. Like I say, your script works on it's own but, I would like to put all the scripts I have into one.

Thanks,

Mark

Posted

When I just add your script in place of the line: "RunWait(@COMSPEC & " /c ping 127.0.0.1 & pause")", I get the following errors:

It's because you put all the code inside function (i guess), but you can not insert functions inside functions, each function should be as seperate block :)...

#include <GuiConstants.au3>

$GUI = GUICreate("Test Script", 300, 200)

$Ping_Button = GUICtrlCreateButton("Ping", 20, 40, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Ping_Button
            Ping1Pressed()
    EndSwitch
WEnd

Func Ping1Pressed()
    $IP_Address = _RunStdOutRead('IPConfig /ALL')
    $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1")
    
    $Ping_Results = _RunStdOutRead('Ping ' & $IP_Address & ' -n 4')
    
    If StringRegExp($Ping_Results, "(?i)\(0%.*?\)") Then
        MsgBox(64, "Done!", StringFormat("Your IP: %s works !", $IP_Address))
        MsgBox(64, "Ping Results", $Ping_Results)
        Return
    Else
        $hOpen_Write = FileOpen("error.txt", 2)
        FileWriteLine($hOpen_Write, StringFormat("IP: %s is down at %s", $IP_Address, @HOUR & ":" & @MIN & ":" & @SEC))
        FileClose($hOpen_Write)
    EndIf
EndFunc

;Function to read from Command Line process.
Func _RunStdOutRead($sRunCmd)
    Local $iPID = Run(@ComSpec & ' /c ' & $sRunCmd, @ScriptDir, @SW_HIDE, 4 + 2)
    Local $sStdOutRead = ""
    
    While ProcessExists($iPID)
        $sStdOutRead &= StdoutRead($iPID)
    WEnd
    
    Return $sStdOutRead
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

It's because you put all the code inside function (i guess), but you can not insert functions inside functions, each function should be as seperate block :)...

OK. I'll try it when I get home from work. :)

Thanks,

Mark

Posted

Awesome, it works!

I figured out what lines of your script to put into my GUI script so I can have all the buttons/functions I needed in one GUI.

Thanks,

Mark

Posted (edited)

Hmm, that script doesn't work for me, it gets my ip fine, but it says my computer is down when it tries to ping it. :S

Edit:

It is because on my system(XP Pro SP2 Swedish) there's a space inbetween the 0 and the %. (ie. it's an error in the reg exp)

Edited by FreeFry
Posted

it's an error in the reg exp)

It's not, in my system there is no space between 0 and % :) - And FYW, i am getting the second message box (with ping results) with text in wrong encoding, my system language is russian :)

If you want to make sure that this will work on every system (almoust), you will have to find another way to get ping results, without using @ComSpec i guess.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted (edited)

If a script doesn't work on all computers(because of language difference), then the script is broken imo.

And the ping statistics given by the dos ping application isn't really anything special, the same could be done with the built in AutoIt functions.

I don't see why you want to use the dos applications/commands if you're trying to move it from dos into AutoIt. :S

Edited by FreeFry
Posted (edited)

New post for this I guess:

I've been doing some digging, and I came up with this:

netsh diag ping adapter

Yes, it's a dos command, and what it does is that it pings the gateway, dns server(s) and your own ip-address, with ALL adapters on your pc(mine has two adapters, one which is not connected).

One thing I noted though is that it successfully pinged my internal ip(192.168.1.4) with the adapter which is not connected(actually it's disabled, and doesn't have a cable plugged in). :S

Edit:

Another command, that might be of use is this:

netsh diag show test

This will do alot of tests(and show info about some other stuff like proxy configurations in iexplore, outlook configurations, etc.), and also does the ping things lik the last command(but this also tries the loopback interface).

One thing to note about these commands is that they might not work on operating systems previous to WinXP(SP2 perhaps, as this is what I use), as it does not work on my Windows 2000 server.

Edited by FreeFry

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
  • Recently Browsing   0 members

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