Jump to content
Sign in to follow this  
PINTO1927

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

 

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By AZJIO
      My Notepad v0.4 (En, Ru)

      Black theme

       
      My_Notepad.7z (560kb sources + EXE)
       
      I wanted to make an example for the help file. But I could not stop, and made more complicated.
    • By Ronster
      I would like to create an auto login program using mouseclicks, controlclicks only, or whatever is required to send characters from Windows 10 On-Screen Keyboard to a User/Password login form. I thought I would start with OSK to NotePad. Using mouseclicks to enter ID/Password seems more secure than typing plain text. Seems like if I can get that to work I should be able to send the characters to any login form. I have tried many things but cannot send a character(s) from OSK to Notepad. Of course manually works great. Here is some code I have tried:
      ControlGetFocus ("Untitled - Notepad")
          ; go to Notepad window
          MouseMove(649, 206 , 0)  ;move to Notepad, then click below
          Sleep (1000)
          MouseClick($MOUSE_CLICK_LEFT,"left")
          ControlGetFocus ("On-Screen Keyboard")
          ; go to OSK window then click on a character key
          MouseMove(642, 807 , 0) ;letter - t
          Sleep (1000)
          MouseClick($MOUSE_CLICK_LEFT,"left")
      OR
      ControlClick("On-Screen Keyboard","","[CLASS:OSKMainClass]","left","",642, 807)
      The above move to the correct position and appear to click but focus is lost to Notepad. Any help would be appreciated.
    • By SkysLastChance
      Run("notepad.exe") GLOBAL $One = ('Line1' & _ 'Line2' & _ 'Line3' & _ 'Line4' & _ 'Line5') ClipPut($One) $Notepad = WinWait("[CLASS:Notepad]", "", 10) ControlSend("Untitled - Notepad", "", "", ("^v")) Instead of having this paste as Line1Line2Line3Line4Line5
      How can I make it paste it into notepad as (without double spacing.)
      Line1
      Line2
      Line3
      Line4
      Line5
    • 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.
×
×
  • Create New...