PINTO1927

Those who have an open file

4 posts in this topic

Hi guys,
you can know the @namecomputer or ip address of the client who opened a notepad file?

I created a chat through a shared notepad .. and I thought of adding an edit "who is online" ..

here it is the code: :lmao:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <GuiButton.au3>
#include <TrayConstants.au3>
#include <Color.au3>
#include <ColorConstants.au3>
#include <ButtonConstants.au3>
#include <GUIComboBox.au3>
#Include <GuiComboBoxEx.au3>
#include <GuiConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <GuiEdit.au3>
#include <Array.au3>
#include <Misc.au3>
#include <ColorConstantS.au3>

Local $hDLL = DllOpen("user32.dll")

FileInstall("C:\birra.ico",@TempDir & "\birra.ico")
GUISetIcon(@TempDir & "\birra.ico", -1)

Global $sFileToCheck = "\\192.168.1.155\cond\chat.txt"
Global $bFileChanged = False
Global $sFileDateTime = _ArrayToString(FileGetTime($sFileToCheck))
AdlibRegister("_CheckFile", 250)

$FormComunicazioni = GUICreate("NAME CHAT", 450, 500, -1, -1)
GUISetBkColor($COLOR_BLACK)
GUISetFont(11, 400, 0, "Calibri")
$EditComunicazioni = GUICtrlCreateEdit("",20, 20, 410, 350, BitOR($ES_READONLY, $CBS_AUTOHSCROLL, $WS_VSCROLL))
GUICtrlSetData(-1, "- Chat" & " " & @MDAY & "\" & @MON & "\" & @YEAR)
$AggiornaComunicazioni = GUICtrlCreateButton("recupera conversazione iniziale", 20, 385, 200, 30)
$edit = GUICtrlCreateEdit("", 20, 430, 340, 55, BitOR($CBS_AUTOHSCROLL, $WS_VSCROLL))
$invia = GUICtrlCreateButton("Invia", 365, 428, 67, 58)

GUISetState(@SW_SHOW)

While 1
   Sleep(10)
   If $bFileChanged Then
      $file= FileOpen ("\\192.168.1.155\cond\chat.txt",0)
      $last_line = FileReadLine ($file, -1)
      _GUICtrlEdit_AppendText($EditComunicazioni, @CRLF & $last_line)
      FileClose($file)
      $sFileDateTime = _ArrayToString(FileGetTime($sFileToCheck))
      $bFileChanged = False
      TrayTip("Stranguglie e previdi", "è presente un nuovo messaggio", 0, $TIP_ICONASTERISK)
      GUISetState(@SW_RESTORE)
   EndIf
   $nMsg = GUIGetMsg()
   Switch $nMsg
   Case $GUI_EVENT_CLOSE
      Exit
   Case $invia
      ClipPut(GUICtrlRead($edit))
      FileWrite("\\192.168.1.155\cond\chat.txt", @CRLF & "[" & @UserName & "]" & " scrive: " & ClipGet())
      Sleep(100)
      Guictrlsetdata($edit,"")
   Case $AggiornaComunicazioni
      $file = FileOpen("\\192.168.1.155\cond\chat.txt", 0)
      $FileContent = FileRead($file)
      _GUICtrlEdit_AppendText($EditComunicazioni, @CRLF & @CRLF & $FileContent)
      FileClose($file)
      GUICtrlSetState($AggiornaComunicazioni, $GUI_DISABLE)
   EndSwitch
WEnd

DllClose($hDLL)

Func _CheckFile()
    If $sFileDateTime <> _ArrayToString(FileGetTime($sFileToCheck)) Then $bFileChanged = True
EndFunc

 

Share this post


Link to post
Share on other sites



you can't. that's because the text file does not remain open while you edit it; it is opened (and closed) only when you save.

but, if you rely on a central file, then you can expand the idea to use another file - a file that each client writes its hostname and username to when launched. so each client can read that file to know who wrote to it.

Share this post


Link to post
Share on other sites

you can give me an example?
otherwise I should add a control, if gui event close than "user has left the chat", conversely, if the chat opening.

Share this post


Link to post
Share on other sites

you have a variable named $sFileToCheck in your script. add another one - call it $sFileOfStats, set it to the same path (and a different name, of course). when your script begins, write to it your hostname, username or whatever.  read it once to see who already wrote to it. at run time, check it for changes to see if anyone wrote anything new. when you close, write that also.

Share this post


Link to post
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

  • Similar Content

    • Skeletor
      By Skeletor
      Hi Guys,
      When I used to scratch the surface with Delphi5, I could only create a simple Notepad program.
      Now that I'm into AutoIt, I've created just a bare bone Notepad.
      Can be improved, but maybe this will be useful for those, like me, starting out with programming.
      I know there are way better notepads out there like Aupad, but,
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <APIDlgConstants.au3> #include <Memory.au3> #include <WinAPIDlg.au3> #include <WinAPIFiles.au3> Opt('WinTitleMatchMode', 3) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Notepad", 620, 440, 192, 124) $MenuItem1 = GUICtrlCreateMenu("File") $MenuItem4 = GUICtrlCreateMenuItem("New" & @TAB & "Ctrl+N", $MenuItem1) $MenuItem5 = GUICtrlCreateMenuItem("Open" & @TAB & "Ctrl+O", $MenuItem1) $MenuItem6 = GUICtrlCreateMenuItem("Save" & @TAB & "Ctrl+S", $MenuItem1) $MenuItem17 = GUICtrlCreateMenuItem("Print" & @TAB & "Ctrl+P", $MenuItem1) $MenuItem7 = GUICtrlCreateMenuItem("Exit" & @TAB & "Ctrl+W", $MenuItem1) $MenuItem2 = GUICtrlCreateMenu("Edit") $MenuItem8 = GUICtrlCreateMenuItem("Undo" & @TAB & "Ctrl+Z", $MenuItem2) $MenuItem9 = GUICtrlCreateMenuItem("Cut" & @TAB & "Ctrl+X", $MenuItem2) $MenuItem10 = GUICtrlCreateMenuItem("Copy" & @TAB & "Ctrl+C", $MenuItem2) $MenuItem11 = GUICtrlCreateMenuItem("Paste" & @TAB & "Ctrl+V", $MenuItem2) $MenuItem12 = GUICtrlCreateMenuItem("Delete" & @TAB & "Del", $MenuItem2) $MenuItem16 = GUICtrlCreateMenu("Format") $MenuItem19 = GUICtrlCreateMenuItem("Word Wrap", $MenuItem16) $MenuItem18 = GUICtrlCreateMenuItem("Font", $MenuItem16) $MenuItem15 = GUICtrlCreateMenu("View") $MenuItem20 = GUICtrlCreateMenuItem("Status Bar", $MenuItem15) $MenuItem3 = GUICtrlCreateMenu("Help") $MenuItem13 = GUICtrlCreateMenuItem("View Help", $MenuItem3) $MenuItem14 = GUICtrlCreateMenuItem("About Notepad" & @TAB & "F1", $MenuItem3) $Edit1 = GUICtrlCreateEdit("", 0, 0, 620, 420, $ES_WANTRETURN) GUICtrlSetFont($Edit1, 10, 400, -1, "Lucida Console") GUICtrlSetData(-1, "") Dim $Form1_AccelTable[11][2] = [["^n", $MenuItem4], ["^o", $MenuItem5], ["^s", $MenuItem6], ["^p", $MenuItem17], ["^w", $MenuItem7], ["^z", $MenuItem8], ["^x", $MenuItem9], ["^c", $MenuItem10], ["^v", $MenuItem11], ["{DEL}", $MenuItem12], ["{F1}", $MenuItem14]] GUISetAccelerators($Form1_AccelTable) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Warning If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(52, "Notepad Closing", "Are you sure you want to exit?") Select Case $iMsgBoxAnswer = 6 ;Yes Exit Case $iMsgBoxAnswer = 7 ;No EndSelect #EndRegion --- CodeWizard generated code Start --- Case $MenuItem4 GUICtrlSetData($Edit1, "") Case $MenuItem5 FileOpenDialog("Open Text File", @DesktopDir, "Text File (*.txt)") Case $MenuItem6 $filesave = FileSaveDialog("Save Text File", @DesktopDir, "Text File (*.txt)") $Edit1_Read = GUICtrlRead($Edit1) FileWrite($filesave, $Edit1_Read) Case $MenuItem7 #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Warning If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(52, "Notepad Closing", "Are you sure you want to exit?") Select Case $iMsgBoxAnswer = 6 ;Yes Exit Case $iMsgBoxAnswer = 7 ;No EndSelect #EndRegion --- CodeWizard generated code Start --- EndSwitch WEnd If you don't attempt something, you never know you can actually achieve that goal.
    • chacoya121
      By chacoya121
      plz help how to organize information from notepad or INIfile
      Example:
      0=000308 1=000308 2=000308 3=000308 4=000408 5=000408 6=000408 7=000408 8=000408 9=000408 10=000308 11=000308 12=000308 13=000408 14=000408 15=000408 16=000408 17=000408 18=000408 19=000408 20=000308 21=000308 22=000308 23=000408 24=000408 25=000408 26=000408 27=000408 28=000408 29=000408 30=000308  0=000308 x 11 total
       1=000408 x 20 total
      2 lines summary all
       
      Thank you
       
    • dreivilo47
      By dreivilo47
      I have a Dutch version of Windows 10.
      The Dutch word for "File" = "Bestand" and for "Page Setup" = "Pagina-instelling".
      WinMenuSelectItem doesn't select this items.  What can be the reason?
       
      Run("notepad.exe") WinWaitActive("[CLASS:Notepad]") WinMenuSelectItem("[CLASS:Notepad]", "", "Bestand", "Pagina-instelling...") Sleep(4000) WinClose("[CLASS:Notepad]")  
    • DeeJay7
      By DeeJay7
      I'm in a requirement to:
      Open multiple files in multiple directories (not all files are .txt files, some are .ini, some without extension). Example: c:\dir\subdir\file1, c:\dir\subdir\file2.ini, c:\dir2\file3 Find 5 or 6 text strings in above files, string may contain special characters (Ex: %hostname%_a1234) Replace them with new string values Take backup of old files and save the updated files. I've tried few scripts and couldn't get the solution.
      Appreciate if anybody could help me to achieve this script.
      Thanks in advance.
       
    • kneze
      By kneze
      Hi
      i start with new script to ad computer names to empty text file. The steps to do this are: Press Button "New CP Name List". Script check if cpnamelist.txt exist and delete it. Script create a new one. Now Script open cpnamelist.txt with notepad and i paste computer names in to this file and save file. How can i stop script until content is saved. I have tried Miscellaneous (winwait etc.) but somthing was wrong.
       
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("CP Name List", 615, 438, 522, 356) $ListCPNameList = GUICtrlCreateList("", 25, 25, 96, 383) $ButtonNewCPNameList = GUICtrlCreateButton("New CP Name List", 130, 120, 105, 25) $ButtonAddCPName = GUICtrlCreateButton("Add CP Name", 130, 30, 105, 25) $ButtonRemoveCPName = GUICtrlCreateButton("Remove CP Name", 130, 60, 105, 25) $InputCPName = GUICtrlCreateInput("", 245, 30, 121, 21) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select ;Case $GUI_EVENT_CLOSE Case $msg = $GUI_EVENT_CLOSE Exitloop Case $msg = $ButtonNewCPNameList MsgBox(0, "Note", "$ButtonNewCPNameList") $CPnameList="D:\AutoIT_Scripts\writefile\temp\temp\cpnamelist.txt" If FileExists($CPnameList) Then FileDelete($CPnameList) ; CPNameList if exist. $hFile = FileOpen("D:\AutoIT_Scripts\writefile\temp\cpnamelist.txt", 1) FileClose($hFile) $sText = FileRead("D:\AutoIT_Scripts\writefile\temp\cpnamelist.txt", 1) $sText = StringReplace($sText, @CRLF, '|') $sText = StringReplace($sText, '||', '|') GUICtrlSetData($ListCPNameList, $sText) Case $msg = $ButtonAddCPName MsgBox(0, "Note", "$ButtonAddCPName") Case $msg = $ButtonRemoveCPName MsgBox(0, "Note", "$ButtonRemoveCPName") EndSelect WEnd func terminate() ;exit Exit 0 EndFunc