Jump to content

Help convert from BAT to AutoIt


wowmarkb
 Share

Recommended Posts

This works in a bat file but, I would like to have it included in my Autoit file with all the other scripts I have.

Can you all help me make the correct changes to make it work in AutoIt?

-----

@echo off

if exist error.txt del error.txt >NUL

:pingtest

for /f "delims=" %%a in (pingme.txt) do call :PROCESS %%a

::wait 30 seconds before continuing

ping localhost -n 30 > NUL

goto :pingtest

:PROCESS

ping %1 -n 4

if ERRORLEVEL 1 goto IPERROR

echo.

echo.

echo.

echo Your IP: %1 works !

goto :eof

:IPERROR

echo IP: %1 is down at %time% >> error.txt

-----

Thanks,

Mark

Link to comment
Share on other sites

Hi,

I guess you can write it from start without translating it.

Have a look at FileRead or _FileReadToArray and For Next and Ping

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

A long time i didn't work with bats, but here is a little blind attempt to translate/rewrite the code on AutoIt :) :

$sError_Data = ""
$hOpen_Read = FileOpen("pingme.txt", 1)
$i = 1

While 1
    $Line = FileReadLine($hOpen_Read, $i)
    If @error = -1 Then ExitLoop
    
    Ping($Line, 4000)
    
    If Not @error Then
        MsgBox(64, "Done!", StringFormat("Your IP: %s works !", $Line))
        ExitLoop
    EndIf
    
    $i += 1
    $sError_Data &= StringFormat("IP: %s is down at %s", $Line, @HOUR & ":" & @MIN & ":" & @SEC) & @CRLF
    
    ;wait 30 seconds before continuing
    Sleep(30 * 1000)
WEnd

FileClose($hOpen_Read)

If $sError_Data <> "" Then
    $hOpen_Write = FileOpen("error.txt", 2)
    FileWrite($hOpen_Write, $sError_Data)
    FileClose($hOpen_Write)
EndIf
Edited by MsCreatoR

 

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

Link to comment
Share on other sites

Hi,

I guess you can write it from start without translating it.

Have a look at FileRead or _FileReadToArray and For Next and Ping

Mega

Well, I would but, I'm no programmer. So far, I have just found scripts and modifed them since I cannot write code from scratch. (I can do a little DOS and write a bat file but, that's about it.)

When I get home I'll try the code from MsCreatoR.

Thanks,

Mark

Link to comment
Share on other sites

Hmm, it didn't work. It opened a pingme.txt with nothing in it and a systray icon that says the autoit is paused. ??

I'm trying to take two bat files and make one AutoIt script that "does it all" :)

Bat file 1 gives me the "myip.txt" file that has only the actual address with no extra characters in it, like: xx.xx.xxx.xx

Bat file 2 takes that ip address from "myip.txt" and pings it- displaying the results in a DOS window.

Here's Bat file 1 & how it gets the IP Address & strips the "IP Adress...." (maybe we can simplify a bit with AutoIt ?):

-----Bat file 1-----

@echo off

For /F "tokens=16 delims= " %%A in ('IPConfig /ALL ^| Find /I "Host Name"') Do Set host_var=%%A #There is a space after delims= unless there is a different character.

For /F "tokens=15 delims= " %%B in ('IPConfig /ALL ^| Find /I "IP Address"') Do Set ip_var=%%B

For /F "tokens=13 delims= " %%C in ('IPConfig /ALL ^| Find /I "Default Gateway"') Do Set dg_var=%%C

For /F "tokens=12 delims= " %%D in ('IPConfig /ALL ^| Find /I "Physical"') Do Set mac_var=%%D

echo %ip_var% > myip.txt

:END

-----Bat file 2-----

@echo off

if exist error.txt del error.txt >NUL

:pingtest

for /f "delims=" %%a in (myip.txt) do call :PROCESS %%a

::wait 30 seconds before continuing

ping localhost -n 30 > NUL

goto :pingtest

:PROCESS

ping %1 -n 4

if ERRORLEVEL 1 goto IPERROR

echo.

echo.

echo.

echo If you see 4 replies, your IP Address works !

goto :eof

:IPERROR

echo IP: %1 is down at %time% >> error.txt

-----

Thanks again for your help,

Mark

Link to comment
Share on other sites

It opened a pingme.txt with nothing in it and a systray icon that says the autoit is paused. ??

It's open in read mode, and the pause is because you click the tray icon :) - put #NoTrayIcon to the begining of your script to hide icon.

Maybe it would be better if you just describe what exactly do you need from script to do?

 

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

Link to comment
Share on other sites

It's open in read mode, and the pause is because you click the tray icon :) - put #NoTrayIcon to the begining of your script to hide icon.

Maybe it would be better if you just describe what exactly do you need from script to do?

I clicked tray icon becuase it seems to be not doing anything after waiting 30+ seconds.

Here's exactly what I'm trying to do:

1) Run ipconfig to determine the computer's IP Address. I do not want to use this script:

-----

line $ip = @IPAddress1

$ping = Ping($ip)

MsgBox(32,"","Tims(ms) : " & $ping)

-----

...because it does not give the real IP Address info. (Like when ethernet cable is unplugged, it doesn't say "Media Disconnected", it gives 127.0.0.1.)

2) From the results "IP Address............xx.xx.xxx.xx, separate out only the numbers.

3) Ping the IP Address and show the results.

Mark

Link to comment
Share on other sites

There's macros that contains your ipaddress(es), they're called @IPAddress1, @IPAddress2, etc.

You could just do:

For $i = 1 To 4
    Ping(@IpAddress1)
    If @error Then
        MsgBox(0, "Error", @IPAddress1 & " is unreachable")
        Exit
    EndIf
NextoÝ÷ Ù8hºH±ç§¢··²í¢§*.®'h¶'¶­"v·¬³
.Ø"½ì¨»*.¬°
Ê·ö·z§uªèº×«¢Ø^¯¬z+p¢é]m쨺·±µêçjX©Ø­!ü¨»§¶Úç${^®w­rçyËb¾+r"²Ì¨¹Ê.Úb0Â
(W¢f®¶­seD57F'GW ¤FÒb33c·eôÒD5æÖUFôgV÷C·wwrævöövÆRæ6öÒgV÷C²Âb33c¶÷46÷VçBÒ ¤f÷"b33c¶ÒFò@ ærb33c·eô bW'&÷"FVâWDÆö÷ b33c¶÷46÷VçB³Ò¤æW@ ¤bb33c¶÷46÷VçBfÇC²BFVà ×6t&÷ÂgV÷C´W'&÷"gV÷C²Âb33c¶÷46÷VçBfײgV÷C²æw27V676VVFVBÂgV÷C²fײb33c·eôfײgV÷C²2VFW"&V6&ÆR÷"÷Rb33·&Rfær&ö&ÆV×2b33·6VVærb33²BgV÷C²¤VÇ6P ×6t&÷ÂgV÷Cµ7V66W72gV÷C²Âb33c·eôfײgV÷C²v2ævVBgV÷C²fײb33c¶÷46÷VçBfײgV÷C²7V66W76gVÆÇÂ6VV×2ƶRBb33·2v÷&¶ærfæRgV÷C²¤VæD`
Edited by FreeFry
Link to comment
Share on other sites

Hi FreeFry!

Using Microsoft article 314067 as a guide, under "Manual troubleshooting" Method 2 suggests you ping the local host IP Address. It says, "If the loopback test succeeds (ping 127.0.0.1) but you cannot ping the local IP address, there may be an issue with the routing table or with the network adapter driver."

My experience has been if you cannot ping your own IP Address, it is a ethenrnet driver or firewall issue and this would help me identify this. (Most likely it is a firewll issue.)

The article goes on to say- "If you can ping both the loopback address (127.0.0.1) and your IP address but you cannot ping any other IP addresses, use the Arp tool to clear out the Address Resolution Protocol (ARP) cache." Rarely have I had to do this but, that is why I sometimes use this procedure to isolate Internet connection problems.

Rarely do I have a customer (I work at an ISP) ping their own IP Address but, I want it "just in case." I start with having them try and ping Google by IP (64.233.167.99). Then if I cannot isolate problem (firewall, router, reset modem, etc.) then I dig in with steps from Microsoft article 314067.

The problem with just using value "@IPAddress1" is that sometimes, that value is 127.0.0.1 and not what I would call the true IP Address- that may be "@IPAddress2". I unplugged my ethernet cable and it gave me 127.0.0.1- I want it to say "media Disconnected"- like it does when I use ipconfig command.

I have all other scripts working except this one- it seems to be the toughest. I think it is because we are the IP Address is a varible.

Thanks,

Mark

Link to comment
Share on other sites

Hmm, I see.

I guess you could 'scan' the @IpAddress macros for a correct ip address like this:

Dim $v_Ip[4] = [@IPAddress1, @IPAddress2, @IPAddress3, @IPAddress4]
For $i = 0 To 3
    If $v_Ip[$i] <> "127.0.01" And $v_Ip[$i] <> "0.0.0.0" Then
        $v_Ip = $v_Ip[$i]
        ExitLoop
    EndIf
Next

MsgBox(0, "Your 'correct' ip is", $v_Ip)

and then use my previous code to ping the 'correct' ip...

Edited by FreeFry
Link to comment
Share on other sites

1) Run ipconfig to determine the computer's IP Address

....

2) From the results "IP Address............xx.xx.xxx.xx, separate out only the numbers.

3) Ping the IP Address and show the results.

Try this:

$IP_Address = _RunStdOutRead('For /F "tokens=15 delims= " %i in (''IPConfig /ALL ^| Find /I "IP-"'') Do Set IP=%i')
$IP_Address = StringStripWS(StringRegExpReplace($IP_Address, "(?i)(?s).*Set IP=(.*?)$", "\1"), 3)

Ping($IP_Address, 4000)

If Not @error Then
    MsgBox(64, "Done!", StringFormat("Your IP: %s works !", $IP_Address))
    Exit
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


;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

As you can see, i used only IP-, because in my system, «Address» is not present, i have «Адрес» instead :) (on russian).

 

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

Link to comment
Share on other sites

Thanks for your reply.

You missed my point about NOT using the @IpAddress macros, though. The reason is stated right in the AutoIt Online Documentation , Macro Reference section at: http://www.autoitscript.com/autoit3/docs/macros.htm - it says "IP address of first network adapter, tends to return 127.0.0.1 on some computers." I absoulutely cannot use this macro because of this.

When the ethernet cable is unplugged, running the macro will not tell you- it only gives a "127.0.0.1". I want it to say "Media State . . . . . . . . . . . : Media disconnected"- this gives the correct info.

Mark

Link to comment
Share on other sites

@wowmarkb

Have you seen my post? :) is this what you need?

 

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

Link to comment
Share on other sites

If you don't belive my method is accurate or enough to determine the state of the connection, then I assume that there's a more reliable way by using WMI, or possibly DllCalls, which would take out the hassle with dealing with the ipconfig result.. I'm going to go looking for it. :)

Link to comment
Share on other sites

it creates the error.txt file that says "IP: is down at 03:57:16". Not sure why.

Probably because IP not found, try to remove - after IP in search line...

$IP_Address = _RunStdOutRead('For /F "tokens=15 delims= " %i in (''IPConfig /ALL ^| Find /I "IP"'') Do Set IP=%i')
$IP_Address = StringStripWS(StringRegExpReplace($IP_Address, "(?i)(?s).*Set IP=(.*?)$", "\1"), 3)

Ping($IP_Address, 4000)

If Not @error Then
    MsgBox(64, "Done!", StringFormat("Your IP: %s works !", $IP_Address))
    Exit
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


;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

Link to comment
Share on other sites

Probably because IP not found, try to remove - after IP in search line...

$IP_Address = _RunStdOutRead('For /F "tokens=15 delims= " %i in (''IPConfig /ALL ^| Find /I "IP"'') Do Set IP=%i')
$IP_Address = StringStripWS(StringRegExpReplace($IP_Address, "(?i)(?s).*Set IP=(.*?)$", "\1"), 3)

Ping($IP_Address, 4000)

If Not @error Then
    MsgBox(64, "Done!", StringFormat("Your IP: %s works !", $IP_Address))
    Exit
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


;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
---------------------

OK, great- that pops up message box "Your IPxx.xx.xxx.xx works!"

Now, if we can take that IP Address and ping it and have a box that shows the ping results, I would be done with this project.

Mark

Link to comment
Share on other sites

if we can take that IP Address and ping it and have a box that shows the ping results, I would be done with this project.

$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)
    Exit
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

;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

Link to comment
Share on other sites

$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)
    Exit
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

;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
---------

It works, YOU ROCK!!! :)

Thank you so much- that is what I have been trying to achieve since Friday.

Mark

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...