Jump to content

Recommended Posts

Posted (edited)

This is my first GUI program with AUTOIT. Using the latest Beta. So far the program allows new names to added or removed from a list. Would like to change the list to a combo box. Also would like to be able to have the program find the Computer or User names with out manually entering them. The program can send a message to One user or all users. It uses a .ini file to store the Computer/ User names. Current location needs to be c:\NetSend for the programm to find the .ini file. Program may be able to tell you what domain you are on. Unable to test this do to being on a work group network. May be using the wrong Macro to find the domain. For right now the what ever is add to the .ini file via the programm will show up as user = user. The program uses the value that the key is to. Example key = user. The key will show up in the list what ever the key is equal to will be the name that net send will send to.

#include <GUIConstants.au3>


GUICreate("Net Send Interface"); will create a dialog box that when displayed is centered

$Car = "Car"
GUICtrlCreateLabel("Enter Computer Name to be added to list", 10, 5, 200)
$ComputerNameInput = GUICtrlCreateInput("", 10, 20, 100, 20)

$AddComputerNameBtn = GUICtrlCreateButton("Add", 10, 45, 75, 25)
$RemoveComputerNameBtn = GUICtrlCreateButton("Remove", 100, 45, 75, 25)


GUICtrlCreateLabel("Network Computers", 10, 85, 200)
GUICtrlCreateLabel("Domain Name: " & @LogonDomain, 125, 85, 200)
$NetworkList = GUICtrlCreateList("", 10, 100, 100, 200)
GUICtrlSetLimit(-1, 200)   ; to limit horizontal scrolling

GUICtrlCreateLabel("Text Message to send", 10, 300, 200)
$TextMessageInput = GUICtrlCreateInput(" ", 10, 315, 350, 20)

$SendTextBtn = GUICtrlCreateButton("Send", 10, 350, 75, 25)

$ClearTextMessageBtn = GUICtrlCreateButton("Clear", 100, 350, 75, 25)

$SendToAllBtn = GUICtrlCreateButton("Send To All", 190, 350, 75, 25)

$CloseBtn = GUICtrlCreateButton("Close", 300, 350, 75, 25)
NetworkComputerList()
GUISetState()
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
   $msg = GUIGetMsg()
   
   Select
      Case $msg = $AddComputerNameBtn
         IniWrite("C:\NetSend\NetworkComputers.ini", "NetworkList", GUIRead($ComputerNameInput), GUIRead($ComputerNameInput))
         GUICtrlSetData($NetworkList, "")
         NetworkComputerList()
         GUICtrlSetData($ComputerNameInput, "")
         
      Case $msg = $RemoveComputerNameBtn
         IniDelete("C:\NetSend\NetworkComputers.ini", "NetworkList", GUIRead($NetworkList))
         GUICtrlSetData($NetworkList, "")
         NetworkComputerList()
         
      Case $msg = $SendTextBtn
         $MessageSentTo = IniRead("C:\NetSend\NetworkComputers.ini", "NetworkList", GUIRead($NetworkList), "NotFound")
         RunWait(@ComSpec & " /c " & "net send " & $MessageSentTo & GUIRead($TextMessageInput))
         
      Case $msg = $ClearTextMessageBtn
         GUICtrlSetData($TextMessageInput, "")
         
      Case $msg = $SendToAllBtn
         RunWait(@ComSpec & " /c " & "net send * " & GUIRead($TextMessageInput))
         
      Case $msg = $CloseBtn
         Exit
   EndSelect
Wend

Func NetworkComputerList()
   $file = FileOpen("C:\NetSend\NetworkComputers.ini", 0)
   
  ; Check if file opened for reading OK
   If $file = -1 Then
      MsgBox(0, "Error", "Unable to open file.")
      Exit
   EndIf
   
  ; Read in lines of text until the EOF is reached
   While 1
      $ReadLine = FileReadLine($file)
      If @error = -1 Then ExitLoop
      $KeyFind = StringLeft($ReadLine, 100)
      $KeyFound = StringInStr($KeyFind, "[")
      If $KeyFound = 0 Then
         $Result = StringInStr($KeyFind, "=")
         $Final = StringLeft($KeyFind, $Result - 1)
         GUICtrlSetData($NetworkList, $Final & "|")
      EndIf
      
   Wend
   
   FileClose($file)
EndFunc  ;==>NetworkComputerList

Will add comments later. Sorry for the missing part of the Code slow connection on my end timed the post out.

Edited by nigma_x
Posted

Hi,

the skript brake atĀ  line 37 whis ErrorĀ  "Unknown function name" for GUIRead,

what's wrong ?

Artus

<{POST_SNAPBACK}>

Replace GuiRead with GuiCtrlRead (for latest beta)

:lmao:

Posted

i also made a network char prog using net send to :lmao:

#include <GUIConstants.au3>
#include <Process.au3>

_RunDos("net view" & " > " & @TempDir & "\temp.txt")

$hello = FileOpen(@TempDir & "\temp.txt", 0)

GUICreate("Network Chat", 300, 130)
$computer = GUICtrlCreateList ("", 5,40,121,97)

While 1
   $line = FileReadLine($hello)
   If @error = -1 Then ExitLoop
   If StringInStr($line, "\\") Then
      GUICtrlSetData($computer,StringMid( (StringStripWS($line, 8)), 3))
   EndIf
Wend

FileClose($hello)

FileDelete(@TempDir & "\temp.txt")

GUICtrlCreateLabel ("Select the computer to send your message to.",  12, 5, 120, 30)
GUICtrlCreateLabel ("Please enter your message.",  150, 87, 150, 15)       
$msg1 = GUICtrlCreateInput ("", 137, 103, 156, 20)
$send = GUICtrlCreateButton ("Send",  137, 5, 156, 80)
GuiSetState()

While 1
    $msg = GUIGetMsg()
    if $msg = $send then
       _RunDos("net send " & GUICtrlRead($computer) & " " & GUICtrlRead($msg1))
    endif
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

mines not as advanced but o:)

qq

  • 2 weeks later...
Posted

Here is an updated version. This one has a menu function for adding new users. Problem is I'm still learning how to create child windows. The program closes when you close the child window. Any help would be great on how to solve this.

Program now tries to find other users on the network. Must use the find button located in the child Window after clicking on menu Tools then computer names.

#include <GUIConstants.au3>


GUICreate("Net Send Interface"); will create a dialog box that when displayed is centered
$ToolsMenu = GUICtrlCreateMenu("&Tools")
$Toolsitem = GUICtrlCreateMenuitem("Computer Names", $ToolsMenu)

GUICtrlCreateLabel("Enter Computer Name to be added to list", 10, 5, 200);Label for Input box
$ComputerNameInput = GUICtrlCreateInput("", 10, 20, 100, 20)             ; The input box for typing in a name to be added

$AddComputerNameBtn = GUICtrlCreateButton("Add", 10, 45, 75, 25); Button to take the input from ComputerNameInput var and add it to a .ini file
$RemoveComputerNameBtn = GUICtrlCreateButton("Remove", 100, 45, 75, 25); This button will remove a name from the .ini file 


GUICtrlCreateLabel("Network Computers", 10, 85, 200) 
GUICtrlCreateLabel("Domain Name: " & @LogonDomain, 125, 85, 200); Label that shows what domain you are on

If WinActive("Messenger Service") Then 
   $MessageRecieved = WinGetText("Messenger Service", "")
   GUICtrlCreateLabel(" " & $MessageRecieved, 125, 105, 270, 100)
EndIf



$NetworkList = GUICtrlCreateList("", 10, 100, 100, 200)
GUICtrlSetLimit(-1, 200)   ; to limit horizontal scrolling

GUICtrlCreateLabel("Text Message to send", 10, 300, 200)
$TextMessageInput = GUICtrlCreateInput(" ", 10, 315, 350, 20)

$SendTextBtn = GUICtrlCreateButton("Send", 10, 350, 75, 25)

$ClearTextMessageBtn = GUICtrlCreateButton("Clear", 100, 350, 75, 25)

$SendToAllBtn = GUICtrlCreateButton("Send To All", 190, 350, 75, 25)

$CloseBtn = GUICtrlCreateButton("Close", 300, 350, 75, 25)
NetworkComputerList()
GUISetState()
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
   $msg = GUIGetMsg()
   If $msg = $Toolsitem Then
     ;Runs the function to find computer names on the network.
      FindComputerNames()
   EndIf
   Select
      Case $msg = $AddComputerNameBtn
         IniWrite("C:\NetSend\NetworkComputers.ini", "NetworkList", GUIRead($ComputerNameInput), GUIRead($ComputerNameInput))
         GUICtrlSetData($NetworkList, "")
         NetworkComputerList()
         GUICtrlSetData($ComputerNameInput, "")
         
      Case $msg = $RemoveComputerNameBtn
         IniDelete("C:\NetSend\NetworkComputers.ini", "NetworkList", GUIRead($NetworkList))
         GUICtrlSetData($NetworkList, "")
         NetworkComputerList()
         
      Case $msg = $SendTextBtn
         If GUIRead($NetworkList) = "" Then
            MsgBox(0, "Error:", "Please make a selection from the Network Computer list.")
         Else
            $MessageSentTo = IniRead("C:\NetSend\NetworkComputers.ini", "NetworkList", GUIRead($NetworkList), "NotFound")
            RunWait(@ComSpec & " /c " & "net send " & $MessageSentTo & GUIRead($TextMessageInput))
         EndIf
         
      Case $msg = $ClearTextMessageBtn
         GUICtrlSetData($TextMessageInput, "")
         
      Case $msg = $SendToAllBtn
         RunWait(@ComSpec & " /c " & "net send * " & GUIRead($TextMessageInput))
         
      Case $msg = $CloseBtn
         Exit
   EndSelect
   
Wend

Func NetworkComputerList()
   $file = FileOpen("C:\NetSend\NetworkComputers.ini", 0)
   
  ; Check if file opened for reading OK
   If $file = -1 Then
      
   Else
     ; Read in lines of text until the EOF is reached
      While 1
         $ReadLine = FileReadLine($file)
         If @error = -1 Then ExitLoop
         $KeyFind = StringLeft($ReadLine, 100)
         $KeyFound = StringInStr($KeyFind, "[")
         If $KeyFound = 0 Then
            $Result = StringInStr($KeyFind, "=")
            $Final = StringLeft($KeyFind, $Result - 1)
            GUICtrlSetData($NetworkList, $Final & "|")
         EndIf
      Wend
      
      FileClose($file)
   EndIf
   
   
EndFunc  ;==>NetworkComputerList

;Func GetMessageService()
;WinActivate("Messenger Service")
;If WinActive("Messenger Service") Then
;$MessageRecieved = WinGetText("Messenger Service", "")
;$MessageCount = StringLen ( $MessageRecieved )
;$MessageCorrected = StringRight($MessageRecieved,$MessageCount - 2 )
;GUICtrlCreateLabel(" " & $MessageCorrected, 125, 105, 270, 100)
; WinActivate("Net Send Interface")
;EndIf
;EndFunc  ;==>GetMessageService

Func FindComputerNames()
   GUICreate("Find Computer Menu", 300, 200)
   
   GUICtrlCreateLabel("Enter Computer Name to be added to list", 10, 5, 200)
   $ComputerNameInput = GUICtrlCreateInput("", 10, 25, 100, 20)
   
   $NetworkList = GUICtrlCreateList("", 205, 20, 90, 190)
   GUICtrlSetLimit(-1, 200)   ; to limit horizontal scrolling
   
   $AddComputerNameBtn = GUICtrlCreateButton("Add", 10, 60, 75, 25)
   $RemoveComputerNameBtn = GUICtrlCreateButton("Remove", 100, 60, 75, 25)
   
   $FindMenu = GUICtrlCreateButton("Find", 10, 150, 75, 25)
   $CloseFindMenuBtn = GUICtrlCreateButton("Close", 100, 150, 75, 25)
   NetworkComputerList()
   GUISetState()
   $FindMenuMsg = 0
   While $FindMenuMsg <> $GUI_EVENT_CLOSE
      $FindMenuMsg = GUIGetMsg()
      Select
         
         Case $FindMenuMsg = $AddComputerNameBtn
            IniWrite("C:\NetSend\NetworkComputers.ini", "NetworkList", GUIRead($ComputerNameInput), GUIRead($ComputerNameInput))
            GUICtrlSetData($NetworkList, "")
            NetworkComputerList()
            GUICtrlSetData($ComputerNameInput, "")
            
         Case $FindMenuMsg = $RemoveComputerNameBtn
            IniDelete("C:\NetSend\NetworkComputers.ini", "NetworkList", GUIRead($NetworkList))
            GUICtrlSetData($NetworkList, "")
            NetworkComputerList()
            
         Case $FindMenuMsg = $FindMenu
           ; Opens a command prompt to run the net view command and send the output to C:\NetSend\netview.txt.
            RunWait(@ComSpec & " /c " & "net view > c:\netsend\netview.txt")
           ; Opens the file C:\NetSend\netview.txt to be read by the program.
            $file = FileOpen("C:\NetSend\netview.txt", 0)
            
           ; Check if C:\NetSend\netview.txt is opened and ok for reading.
            If $file = -1 Then
               MsgBox(0, "Error", "Unable to open file.")
               Exit
            EndIf
           ; Read in lines of text until the EOF is reached
            While 1
               $ReadLine = FileReadLine($file)
               If @error = -1 Then ExitLoop
              ; Reads the entire line.
               $LineRead = StringLeft($ReadLine, 100)
              ; Checks to see if the line contains "\\" in the line.
               $ComputerFound = StringInStr($LineRead, "\\")
              ; If the line contains "\\" then run the if statement.
               If $ComputerFound = 1 Then
                 ; Removes the "\\" from the line and with out changing the C:\NetSend\netview.txt file.
                  $RemoveBackSlash = StringTrimLeft($LineRead, 2)
                 ; Creates or changes the NetworkComputer.ini file.  Will Create an INI file that Will have NetworkList as the section
                 ; and the $Var value ot $RemoveBackSlash as the key and value of the key for the ini file.
                  IniWrite("C:\NetSend\NetworkComputers.ini", "NetworkList", $RemoveBackSlash, $RemoveBackSlash)
               EndIf
            Wend
           ; Closes the c:\netsend\netview.txt file.
            FileClose($file)
           ; Checks to see if the c:\netsend\netview.txt file exist.
            If FileExists("c:\netsend\netview.txt") Then
              ; If the c:\netsend\netview.txt exist delete the file
               FileDelete("c:\netsend\netview.txt")
            EndIf
            NetworkComputerList()
            
         Case $FindMenuMsg = $CloseFindMenuBtn
            Exit

      EndSelect
      
   Wend
EndFunc  ;==>FindComputerNames
Posted

Sorry for the double post. Connection crapped out during the send of the post. So I sent it a second time. Ignore the first duplicate. Second one has the full code.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...