Jump to content

Recommended Posts

Posted

hello,

I'm new to autoit, so I'm still trying to get the hang of it. I'm trying to write a script that will analyze the output of ipconfig. my ultimate goal is to return the MAC address of wireless adapters only, but right now I'm stuck at counting the lines of the output!

Run("cmd.exe")
sleep(500)
Send("ipconfig /all > C:\lol.txt{ENTER}")
sleep(100)
WinClose("C:\WINDOWS\system32\cmd.exe")
$ipconfig = FileOpen("C:\lol.txt", 0)
 If $ipconfig = -1 Then
     MsgBox(0,"kk","Failed to open file")
 EndIf   
 $linesttl = _FileCountLines($ipconfig)
 MsgBox(0,"lol",$linesttl)

this script returns 0 in the message box. However...

$file = FileOpenDialog("What file","","Text Files (*.txt)")
$result = _FileCountLines($file)
MsgBox(0,"lol",$result)

This script returns the correct number of lines when I manually select the output generated by the first script. What am I missing?

Posted

Your problem is that you're trying to count the lines of $ipconfig, and $ipconfig isn't the file path.. ipconfig is the command that says to open the file. Give this a shot.

Dim $file = "C:/lol.txt" ; File path
$ipconfig = FileOpen($file, 0) ; Open the file (using the file path specified above)
If $ipconfig = -1 Then
MsgBox(0,"kk","Failed to open file")
EndIf    
$linesttl = _FileCountLines($file)
MsgBox(0,"lol",$linesttl)

:)

Global $arr[2]

$arr[0]="hip"
$arr[1]="hip"
;^^ hip hip array. ^^
Posted

hello,

I'm new to autoit, so I'm still trying to get the hang of it. I'm trying to write a script that will analyze the output of ipconfig. my ultimate goal is to return the MAC address of wireless adapters only, but right now I'm stuck at counting the lines of the output!

Run("cmd.exe")
sleep(500)
Send("ipconfig /all > C:\lol.txt{ENTER}")
sleep(100)
WinClose("C:\WINDOWS\system32\cmd.exe")
$ipconfig = FileOpen("C:\lol.txt", 0)
 If $ipconfig = -1 Then
     MsgBox(0,"kk","Failed to open file")
 EndIf   
 $linesttl = _FileCountLines($ipconfig)
 MsgBox(0,"lol",$linesttl)

this script returns 0 in the message box. However...

$file = FileOpenDialog("What file","","Text Files (*.txt)")
$result = _FileCountLines($file)
MsgBox(0,"lol",$result)

This script returns the correct number of lines when I manually select the output generated by the first script. What am I missing?

Hi,

You need to pass the path of lol.txt to _FileCountLines($sFilePath)

(using FileOpen() returns a handle not a path...

using FileOpenDialog() returns a path to the file)

Also you need to give a bigger sleep() so that cmd window gets enough time to pipe the data to the lol.txt file.

#Include <File.au3>

$ipconfig = "C:\lol.txt" 

$PID = Run("cmd.exe")
sleep(100)

Send("ipconfig /all > " & $ipconfig & "{ENTER}")
sleep(500) ; allow enough time for the cmd window to pipe the text to the file.
ProcessClose($PID)

If $ipconfig = -1 Then
     MsgBox(0,"kk","Failed to open file")
EndIf    

$linesttl = _FileCountLines($ipconfig) ; use a path to the file, not the handle
MsgBox(0,"lol",$linesttl)

Cheers

Posted (edited)

I would rather use Run(@Comspec & " /c ipconfig /all > " & $ipconfig, "" , @SW_HIDE)

It's more reliable than a sleep and sending the keys.

Edited by Pain

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
×
×
  • Create New...