MattX Posted September 7, 2005 Posted September 7, 2005 Anyone written or have an idea how to tidy up piped files from say a net user command ? EG - net user>c:\users.txt Open up the txt file and the list of users are split in rows of 3. I want the txt file to be a basic lookup file so the list of users I want in a single column etc. Can anyone point me please in the right direction ?
Valuater Posted September 7, 2005 Posted September 7, 2005 here is s a messenger script utilizing your needs expandcollapse popupDim $QT_web = "www.XPCleanMenu.HostRocket.com" ;delete last listing Filedelete("b.tmp") ;gets the computer list and a few other things RunWait(@ComSpec & ' /c net view > a.tmp', @ScriptDir, @SW_HIDE) ;open the file for working $file = FileOpen("a.tmp", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;Creates new file in which the result will be written FileOpen("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("b.tmp", $line & "|") EndIf Wend FileClose($file) FileDelete("a.tmp") $file2 = FileReadline("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) $Tmesg_win = GuiCreate(" *QTime Station* - Messenger ", 329,145) GUISetIcon($Time_icon) $Icon_1 = GUICtrlCreatePic($Time_Logo, 265, 10, 50, 50) ;Create 2 buttons $button_1 = GUICtrlCreateButton("S&end", 40, 110, 80, 25) GUICtrlSetState(-1,$GUI_DEFBUTTON) $button_2 = GUICtrlCreateButton("C&ancel", 210, 110, 80, 25) ;Create 1 combo box, give focus and populate with contents of b.tmp $combo_1 = GUICtrlCreateCombo( "", 110, 20, 120, 20) GUICtrlSetState(-1,$GUI_FOCUS) GUICtrlSetData(-1,$file2) ;create labels $label_1 = GUICtrlCreateLabel( "C&hoose the PC", 20, 22, 150, 20) ;create text input $text = GUICtrlCreateInput("Message", 25, 70, 280, 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 QTasc") 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_2 Or $msg = $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Tmesg_win) SoundPlay ($Sound_grp,1) case $msg = $button_1 SoundPlay ($Sound_clk,1) $CPUID = GuictrlRead($combo_1) $msg1 = GuictrlRead($text) $var =RunWait(@comspec & " /c net send "& $CPUID &" "& $msg1,"",@sw_hide) ;GUICtrlSetData ( $combo_1, $file2) 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", "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(200) Send("{TAB}") Sleep(100) Send("Messenger") Sleep(100) Send("{ENTER}") Sleep(100) Send("!e") Sleep(100) Send("A") EndFunc ;==>Set_Exit hope it helps
MattX Posted September 7, 2005 Author Posted September 7, 2005 Looks good thanks, not sure about it connecting to a web site and DLing and installing files though....... I'll be looking at your code in regards to the file trimming and see if that will help me.here is s a messenger script utilizing your needsexpandcollapse popupDim $QT_web = "www.XPCleanMenu.HostRocket.com" ;delete last listing Filedelete("b.tmp") ;gets the computer list and a few other things RunWait(@ComSpec & ' /c net view > a.tmp', @ScriptDir, @SW_HIDE) ;open the file for working $file = FileOpen("a.tmp", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;Creates new file in which the result will be written FileOpen("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("b.tmp", $line & "|") EndIf Wend FileClose($file) FileDelete("a.tmp") $file2 = FileReadline("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) $Tmesg_win = GuiCreate(" *QTime Station* - Messenger ", 329,145) GUISetIcon($Time_icon) $Icon_1 = GUICtrlCreatePic($Time_Logo, 265, 10, 50, 50) ;Create 2 buttons $button_1 = GUICtrlCreateButton("S&end", 40, 110, 80, 25) GUICtrlSetState(-1,$GUI_DEFBUTTON) $button_2 = GUICtrlCreateButton("C&ancel", 210, 110, 80, 25) ;Create 1 combo box, give focus and populate with contents of b.tmp $combo_1 = GUICtrlCreateCombo( "", 110, 20, 120, 20) GUICtrlSetState(-1,$GUI_FOCUS) GUICtrlSetData(-1,$file2) ;create labels $label_1 = GUICtrlCreateLabel( "C&hoose the PC", 20, 22, 150, 20) ;create text input $text = GUICtrlCreateInput("Message", 25, 70, 280, 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 QTasc") 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_2 Or $msg = $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Tmesg_win) SoundPlay ($Sound_grp,1) case $msg = $button_1 SoundPlay ($Sound_clk,1) $CPUID = GuictrlRead($combo_1) $msg1 = GuictrlRead($text) $var =RunWait(@comspec & " /c net send "& $CPUID &" "& $msg1,"",@sw_hide) ;GUICtrlSetData ( $combo_1, $file2) 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", "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(200) Send("{TAB}") Sleep(100) Send("Messenger") Sleep(100) Send("{ENTER}") Sleep(100) Send("!e") Sleep(100) Send("A") EndFunc ;==>Set_Exithope it helps<{POST_SNAPBACK}>
MSLx Fanboy Posted September 7, 2005 Posted September 7, 2005 I don't know if you've got it working yet, but StringStripWS should work, just replace any remaining spaces with @CRLF Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate())
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