Jump to content

Family Instant Messenger


jefhal
 Share

Recommended Posts

In order to talk to each other in our house, we have to yell at the top of your lungs. We invested a few hundred dollars in Radio Shack intercoms, but they make a lot of noise and don't work in all parts of the house. I just realized that most of us spend a lot of time in front of the computer, so I put together a really rudimentary instant messenger for the home network. (AIM was just too complex to use, and my kids would not use another commercial IM program). So here it is: Improvements are needed and welcome!

#include <Constants.au3>
#include <GUIConstants.au3>
#include <misc.au3>

dim $line, $varcomputer, $vartext, $indexoff 
dim $message = "", $v_dll = 'user32.dll'
Global $sender
$defaultuser = IniRead("c:\FH-IM.ini","FH-IM Settings","DefaultUser","Choose User")
MsgBox(4096,"Default user",$defaultuser)
GUICreate("FH-IM",180,180,100,100)
GUISetState()
$dad = GUICtrlCreateRadio("Dad",5,5,40,15)
$mom = GUICtrlCreateRadio("Mom",50,5,40,15)
$fam = GUICtrlCreateRadio("Family Room",95,5,85,15)
$kid1 = GUICtrlCreateRadio("kidone",5,25,60,15)
$kid2 = GUICtrlCreateRadio("kidtwo",65,25,60,15)
$evy = GUICtrlCreateRadio("Everyone",5,45,70,15)
$mess = GUICtrlCreateInput("",5,65,170,70,0x0004)
$send = GUICtrlCreateButton("Send",5,145,170,25)
$from = GUICtrlCreateCombo ($defaultuser, 110,41,65,11); create first item
GUICtrlSetData(-1,"Mom|Dad|Kid1|Kid2"); add other item snd set a new default
ControlFocus ( "FH-IM", "", 10 )

While 1         ; Wait for user to select checkboxes and then press the "Go" button to begin routines
    $msg = guigetmsg()
    Select
    
    Case $msg = $GUI_EVENT_CLOSE; If user closes the dialog box the program is ended
        Exit
   ; ExitLoop
;ControlFocus ( "FH-IM", "", 10 )

    Case $msg = $send      ; If user selects the Go button, all checked tasks will be run
   ;if _IsPressed("0d",$v_dll) then 
    $sender = GUICtrlRead(11)
    IniWrite("c:\FH-IM.ini","FH-IM Settings","DefaultUser",$sender)
        if(GuiCtrlRead($dad)  = 1) then 
            $to = "dadcomputer"
        EndIf
        if(GuiCtrlRead($mom)  = 1) then 
            $to = "momcomputer"
        EndIf
        if(GuiCtrlRead($fam)  = 1) then 
            $to = "familycomputer"
        EndIf
        if(GuiCtrlRead($tey)  = 1) then 
            $to = "kidone
        EndIf
        if(GuiCtrlRead($par)  = 1) then 
            $to = "kidtwo"
        EndIf
        if(GuiCtrlRead($evy)  = 1) then 
            $to = "*"
        EndIf
    ;MsgBox(4096,"$mess is: ",guictrlread($mess))
    ;msgbox(4096,"next is: ",StringInStr(guictrlread($mess),@CRLF,0,-1))
            if stringinstr(guictrlread($mess),@CRLF) <> 0 then 
                $message = $sender & "> " & stringright(guictrlread($mess),StringInStr(guictrlread($mess),@CRLF,0,-1)-1) & @CRLF
            Else 
                $message = guictrlread($mess) & @CRLF
            EndIf
    ;MsgBox(4096,"Message = :",$message)
        $pid = run(@comspec & ' /c ' & "net send " & $to & ' "' & $message & '"',@tempdir,@sw_hide,$stdout_child)
        While 1
            $line &= StdoutRead($pid)
            If @error = -1 Then ExitLoop
        Wend
        MsgBox(0, "STDOUT read:", $line)
        GUICtrlSetData(9,$message,"")
        $line = ""
    EndSelect
WEnd

Enjoy!

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

hey.... its cool that you want to change the names and variables..ie $Kid1 and kidone

but you should check the script first for errors... so i cleaned it up

#include <Constants.au3>
#include <GUIConstants.au3>
#include <misc.au3>

dim $line, $varcomputer, $vartext, $indexoff 
dim $message = "", $v_dll = 'user32.dll'
Global $sender
$defaultuser = IniRead("c:\FH-IM.ini","FH-IM Settings","DefaultUser","Choose User")
MsgBox(4096,"Default user",$defaultuser)
GUICreate("FH-IM",180,180,100,100)
GUISetState()
$dad = GUICtrlCreateRadio("Dad",5,5,40,15)
$mom = GUICtrlCreateRadio("Mom",50,5,40,15)
$fam = GUICtrlCreateRadio("Family Room",95,5,85,15)
$kid1 = GUICtrlCreateRadio("kidone",5,25,60,15)
$kid2 = GUICtrlCreateRadio("kidtwo",65,25,60,15)
$evy = GUICtrlCreateRadio("Everyone",5,45,70,15)
$mess = GUICtrlCreateInput("",5,65,170,70,0x0004)
$send = GUICtrlCreateButton("Send",5,145,170,25)
$from = GUICtrlCreateCombo ($defaultuser, 80,41,85,11); create first item
GUICtrlSetData(-1,"Mom|Dad|Kid1|Kid2"); add other item snd set a new default
ControlFocus ( "FH-IM", "", 10 )

While 1          ; Wait for user to select checkboxes and then press the "Go" button to begin routines
    $msg = guigetmsg()
    Select
    
    Case $msg = $GUI_EVENT_CLOSE; If user closes the dialog box the program is ended
        Exit
  ; ExitLoop
;ControlFocus ( "FH-IM", "", 10 )

    Case $msg = $send      ; If user selects the Go button, all checked tasks will be run
  ;if _IsPressed("0d",$v_dll) then 
    $sender = GUICtrlRead(11)
    IniWrite("c:\FH-IM.ini","FH-IM Settings","DefaultUser",$sender)
        if(GuiCtrlRead($dad)  = 1) then 
            $to = "dadcomputer"
        EndIf
        if(GuiCtrlRead($mom)  = 1) then 
            $to = "momcomputer"
        EndIf
        if(GuiCtrlRead($fam)  = 1) then 
            $to = "familycomputer"
        EndIf
        if(GuiCtrlRead($kid1)  = 1) then 
            $to = "kidone"
        EndIf
        if(GuiCtrlRead($kid2)  = 1) then 
            $to = "kidtwo"
        EndIf
        if(GuiCtrlRead($evy)  = 1) then 
            $to = "*"
        EndIf
  ;MsgBox(4096,"$mess is: ",guictrlread($mess))
  ;msgbox(4096,"next is: ",StringInStr(guictrlread($mess),@CRLF,0,-1))
            if stringinstr(guictrlread($mess),@CRLF) <> 0 then 
                $message = $sender & "> " & stringright(guictrlread($mess),StringInStr(guictrlread($mess),@CRLF,0,-1)-1) & @CRLF
            Else 
                $message = guictrlread($mess) & @CRLF
            EndIf
  ;MsgBox(4096,"Message = :",$message)
        $pid = run(@comspec & ' /c ' & "net send " & $to & ' "' & $message & '"',@tempdir,@sw_hide,$stdout_child)
        While 1
            $line &= StdoutRead($pid)
            If @error = -1 Then ExitLoop
        Wend
        MsgBox(0, "STDOUT read:", $line)
        GUICtrlSetData(9,$message,"")
        $line = ""
    EndSelect
WEnd

it works now

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

i made one for our office that looks for the computer name

maybe there is something in here you would like to add to yours???

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

;delete last listing
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, "QTasc")

$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, 150, 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 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_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", "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)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

i made one for our office that looks for the computer name

maybe there is something in here you would like to add to yours???

Thanks Valuater-

I realized after I pasted my original code that I didn't want to show my kids names. I appreciate you doing a "touch up". I definitely plan to steal the way you populate the "TO" field from the "net view" command. Also, the way you make sure that messenger service is turned on is a great idea. I had to do it manually on all but one machine.

On your code, for some reason, the list of machines in there keeps duplicating itself. You have a command to delete b.txt, but it doesn't seem to work on my setup. (WinXP HE)

I'm also still trying to find the best way to have the script on one machine be "aware" of the script running on another. Right now, of course, the message is sent, but does not end up in the same window as the script... ;)

Edited by jefhal
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
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...