Jump to content

Those who have an open file


Recommended Posts

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

 

Link to comment
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.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
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.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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

×
×
  • Create New...