Jump to content

Processing Data from DOS window


cronicl3
 Share

Recommended Posts

Any of those who read my last thread (http://www.autoitscript.com/forum/index.php?showtopic=32358), this is the next step up from what I wanted to accomplish there.

Now that I have the text from the command window, how do I separate/isolate and manipulate values from within that text? Let's say I run "net view" or "net group" and have their outputs that list computers on the network i.e. \\comp1, \\comp2, etc.

Obviously, you can isolate the names of the systems by looking within the outputted text file for a "\\" and ending with a " ". Now I want to take this value and use it within another command, like "telnet [computer name]". Repeat this for all the different computer names I can pick out from the text file.

I understand the programming concepts behind this, but I'm inexperienced with the scripting language and wouldn't even know how to approach it.

Once again, thanks for all your assistance(s) in advance. :)

Edited by cronicl3
Link to comment
Share on other sites

Maybe this can help with ideas

Dim $un = @UserName
Dim $QT_web = "www.ClickTask.com"
$ver = "1.0"

;delete last listing
Filedelete(@TempDir & "\a.tmp")
Filedelete(@TempDir & "\b.tmp")

; make sure net send is running
RunWait("net start messenger","",@SW_HIDE)

;gets the computer list and a few other things
RunWait(@ComSpec & ' /c net view > ' & @TempDir & '\a.tmp',"", @SW_HIDE)
Sleep(300)
;open the file for working
$file = FileOpen(@TempDir & "\a.tmp", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "QT - Error", "Unable to open file.")
    Exit
EndIf

;Creates new file in which the result will be written
FileOpen(@TempDir & "\b.tmp", 1)

; Read in lines of text until the EOF is reached in file a.tmp
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
  ;find the string "\\"
    $result = StringInStr($line,"\\")
      if $result = 1 Then
    ;find next blank
      $blankpos = StringInStr($line," ")
    ;Find length of line
      $len = StringLen($line)
    ;calculate from what position to Trim string to the right
      $len = $len - $blankpos
    ;Trim all characters after the computer name
      $line = StringTrimRight($line, $len)
    ;Trim the //
      $line = StringTrimLeft($line,2)
    ;Write line to file, adding "|"
      FileWrite(@TempDir & "\b.tmp", $line & "|")
      EndIf

Wend

FileClose($file)
FileDelete(@TempDir & "\a.tmp")
$file2 = FileReadline(@TempDir & "\b.tmp", 1)

;install pics
    $Time_Logo = @TempDir & "\Time-logo.jpg"
    FileInstall("C:\XPClean-web\Settings\XPClean-pics\Time.jpg", $Time_Logo)
    $Time_icon = @TempDir & "\Time-Icon.ico"
    FileInstall("C:\XPClean-web\Settings\XPClean-pics\Time-Icon.ico", $Time_icon)
    $Sound_clk = @TempDir & "\Sound_clk.wav"
    FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Clickerx.wav", $Sound_clk)
    $Sound_grp = @TempDir & "\Sound_grp.wav"
    FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Group_open.wav", $Sound_grp)
    $Sound_bar = @TempDir & "\Sound_bar.wav"
    FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\xpinfbar.wav", $Sound_bar)
    $Sound_lnk = @TempDir & "\Sound_lnk.wav"
    FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Notify.wav", $Sound_lnk)


;GUI Start
#include "GUIConstants.au3"
;#include <Process.au3>

;Set GUI
Opt("GUICoordMode", 1)
;Opt("GUINotifyMode", 1)
$Dummy_win = GUICreate('')
$Tmesg_win = GuiCreate("*QTime Station*  -  PC Messenger                                ver " & $ver, 482, 335, -1, -1,-1,$WS_EX_ACCEPTFILES,$Dummy_win);, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUISetFont(9, 400, -1, "MS Sans Serif")
GUISetIcon($Time_icon)
$Icon_1 = GUICtrlCreatePic($Time_Logo, 393, 10, 75, 70)
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, "ClickTask.com")

$Group_1A = GuiCtrlCreateGroup( "Message from: ", 20, 10, 350, 50)
GUICtrlCreateLabel( $un, 40, 30, 150, 20)



;Create 1 combo box, give focus and populate with contents of b.tmp
$Group_1A = GuiCtrlCreateGroup("Message to: ",20, 70, 350, 50)
$combo_1 = GUICtrlCreateCombo("", 130, 87, 120, 20)
GUICtrlSetState(-1,$GUI_FOCUS)
GUICtrlSetData(-1,$file2)
$label_1 = GUICtrlCreateLabel( "C&hoose the PC", 40, 90, 80, 20)


$Group_4 = GuiCtrlCreateGroup("Last Message Sent", 20, 270, 350, 50)
$MSent = GUICtrlCreateLabel("No Recent Messages", 40, 288, 320, 28)

;Create buttons
$button_1 = GUICtrlCreateButton("S&end", 390, 190, 80, 30)
               GUICtrlSetState(-1,$GUI_DEFBUTTON)
$button_2 = GUICtrlCreateButton("Set-Up", 390, 275, 80, 20)
$button_3 = GUICtrlCreateButton("C&ancel",  390, 300, 80, 20)




;create text input
$Group_3 = GuiCtrlCreateGroup("Message Text", 20, 140, 350, 120)
GUICtrlCreateLabel("Please Type in Your Test Message in the Box Below", 40, 165, 310, 20)
GUICtrlCreateLabel("The Message includes the Time, Date, PC and Sender Name", 40, 185, 320, 20)
$text = GUICtrlCreateInput("Message", 40, 215, 310, 20)

;Show the GUI
GuiSetState (@SW_SHOW)
SoundPlay ($Sound_lnk,1)

;sets tray icon
    opt("TrayMenuMode", 1)  ; Default tray menu items (Script Paused/Exit) will not be shown.
    opt("TrayOnEventMode", 1)
;TraySetClick (16); right click
    
    $show_tray = TrayCreateItem ("Show  *QTime Station*")
    TrayItemSetOnEvent (-1, "Set_Show")
    TrayCreateItem ("")
    $upgrade_tray = TrayCreateItem ("Check New Releases")
    TrayItemSetOnEvent (-1, "Set_Update")
    TrayCreateItem ("")
    $setup_tray = TrayCreateItem ("Net-Send Setup")
    TrayItemSetOnEvent (-1, "Set_Setup")
    TrayCreateItem ("")
    $about_tray = TrayCreateItem ("About ClickTask.com")
    TrayItemSetOnEvent (-1, "Set_QT")
    TrayCreateItem ("")
    $exit_tray = TrayCreateItem ("Exit  *QTime Station*")
    TrayItemSetOnEvent (-1, "Set_Exit")
    
    TraySetState ()

$msg = 0
While 1; $msg <> -3
$msg = GuiGetMsg()
Select
case $msg = $button_3 Or $msg = $GUI_EVENT_CLOSE
    GUISetState(@SW_HIDE, $Tmesg_win)
    SoundPlay ($Sound_grp,1)
case $msg = $button_2
;SoundPlay ($Sound_clk,1)
    Call("Set_Setup")
case $msg = $button_1
    SoundPlay ($Sound_clk,1)
    $CPUID = GuictrlRead($combo_1)
    If $CPUID = "" Then
        MsgBox(64,"Send Error 1"," Please choose a PC to  *Send*  to...      ")
        ContinueLoop
    EndIf
    $msg1 = GuictrlRead($text)
    If $msg1 = "" Or $msg1 = "Message" Then
        MsgBox(64,"Send Error 2"," Please Type a  *Text Message*  First...      " )
        ContinueLoop
    EndIf
    $runvar =RunWait(@comspec & " /c net send " & $CPUID & $un & " says:   " & $msg1,"",@sw_hide)
;MsgBox(0,"",$runvar)
    If $runvar > 0 Then
        MsgBox(64,"Send Error 3"," Your Message   *Could Not Be Sent*       " & @CRLF & @CRLF & " Please press the  *Set-Up*  Button    "  & @CRLF & @CRLF & "and press  *Set-Up*  on " & $CPUID & "  " )
        ContinueLoop
    EndIf
    GUICtrlSetData ( $MSent, $msg1)
    EndSelect
WEnd

Exit

;---------------------------- FUNCTIONS ----------------------

Func Set_Update()
    SoundPlay ($Sound_clk,1)
    Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $QT_web)
    WinWaitActive("")
EndFunc

Func Set_Show()
    SoundPlay ($Sound_grp,1)
    GUISetState(@SW_SHOW, $Tmesg_win)
EndFunc  

Func Set_QT()
    SoundPlay ($Sound_grp,1)
    $iMsgBoxAnswer = MsgBox(32, "*QTime Station* ,  by   QTasc (Now ClickTask.com)", "WHO IS,  QT APPRAISAL SERVICE CO ?" & @CRLF & "" & @CRLF & "We are a Real Estate Appraisal Company based in Riverside, California. " & @CRLF & "" & @CRLF & "Thank you." & @CRLF & "" & @CRLF & "", 60)
    Select
        Case $iMsgBoxAnswer = -1;Timeout
        EndSelect
    SoundPlay ($Sound_grp,1)
EndFunc

Func Set_Exit()
    SoundPlay ($Sound_lnk,1)
    Exit
EndFunc  ;==>Set_Exit

Func Set_Setup()
    SoundPlay ($Sound_clk,1)
    GUISetState(@SW_HIDE, $Tmesg_win)
    Run("mmc Services.msc -k netsvcs", @SystemDir)
    WinWaitActive("Services")
    Sleep(300)
    Send("{TAB}")
    Sleep(300)
    Send("Messenger")
    Sleep(300)
    Send("{ENTER}")
    Sleep(300)
    Send("!e")
    Sleep(300)
    Send("A")
    Sleep(300)
    Send("!A")
    Sleep(300)
    Send("!S")
    Sleep(2000)
    MsgBox(64,"Finished Set-up"," If all settings are satisfactory...    " & @CRLF & " Please press  *OK*   ")
    While 3
        If Not WinExists("Messenger Properties") Then ExitLoop
        Sleep(100)
    WEnd
    Sleep(100)
    WinClose("Services")
    
EndFunc  ;==>Set_Exit

8)

NEWHeader1.png

Link to comment
Share on other sites

dont know about love.... but

Welcome

8)

:) What's love got to do - got to do - got to do with it? :P

:D What's love, but a second hand code frag-ment... :D

:party: Everybody shake your flippers! :party:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...