Jump to content

Search the Community

Showing results for tags 'findfirstchangenotification'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 2 results

  1. Let me just share an idea: Two (or more) computers have OneDrive Desktop installed They point to the same OneDrive account: both computers would be synchronized when one of them changes its local OneDrive folder Lets see the first computer as 'server': It is running an AutoIt script ('Main.au3') that is monitoring changes in a text file in its local shared folder The client computer changes a text file with the same name in its relative local shared folder The text line is like a command: with a name of script and parameters The 'Server' computer it is synchronized: Main.au3 detects changes in the local text file Reads the line and execute another script For example: generates a report from a query to a database and save a file in another shared folder FOR SURE, is not an advance solution, just an idea Thanks in advance for your comments See here an example of the Main.au3:
  2. Help file doesn't seems to have an example for _WinAPI_WaitForSingleObject Below a simple adaptation from the _WinAPI_FindNextChangeNotification help example (also posted in the russian forum) i'm using something similar as a way of data transfer between computers having a shared folder #include <WinAPIEx.au3> Local Const $g_sPath = @ScriptDir Global $hDir = _WinAPI_FindFirstChangeNotification($g_sPath, $FILE_NOTIFY_CHANGE_LAST_WRITE) Local $iID, $bBoolean = False While 1 Sleep(1000) ;Adapted from Help File example for _WinAPI_FindFirstChangeNotification function ;My tests without the second parameter seems to have the issue 'can't exit normally' described here: ;https://www.autoitscript.com/forum/topic/180602-readdirectorychangesw-exit/ $iID = _WinAPI_WaitForSingleObject($hDir, 0) Switch $iID Case 0 ; WAIT_OBJECT_0 If $bBoolean = True Then $bBoolean = False Else $bBoolean = True ConsoleWrite('A file was changed in the directory.' & @CRLF) Beep(400,50) EndIf Case Else ContinueLoop EndSwitch If Not _WinAPI_FindNextChangeNotification($hDir) Then MsgBox(0, 'Error', 'Unexpected error.') Exit EndIf WEnd Func OnAutoItExit() _WinAPI_FindCloseChangeNotification($hDir) ConsoleWrite('Bye-bye!' & @CRLF) EndFunc For those interested in the data transfer application, this is what i'm using: Main.au3 #pragma compile(AutoItExecuteAllowed, True) #include <WinAPIEx.au3> ;test directory: Global Const $g_sPath = "C:\Documents and Settings\XP\Escritorio\InterPC\bridge" Global $hDir = _WinAPI_FindFirstChangeNotification($g_sPath, $FILE_NOTIFY_CHANGE_LAST_WRITE) Global $sFileRead Local $aArray Local $iID, $bBoolean = False While 1 Sleep(1000) $iID = _WinAPI_WaitForSingleObject($hDir, 0) Switch $iID Case 0 ; WAIT_OBJECT_0 If $bBoolean = True Then $bBoolean = False Else $bBoolean = True ;ConsoleWrite('A file was changed in the directory.' & @CRLF) ReadLine() ;_RunAU3(".\scripts\AU3_Example.au3", $sFileRead, "", @SW_SHOW, 8) ;in $sFileRead there is a string with this format: AU3_Example.au3|parameter1 'parameter 2' ""parameter 3"" $aArray = StringSplit($sFileRead, "|") _RunAU3(".\scripts\" & $aArray[1], $aArray[2], "", @SW_SHOW, 8) EndIf Case Else ContinueLoop EndSwitch If Not _WinAPI_FindNextChangeNotification($hDir) Then MsgBox(0, 'Error', 'Unexpected error.') Exit EndIf WEnd Func OnAutoItExit() _WinAPI_FindCloseChangeNotification($hDir) ;ConsoleWrite('Bye-bye!' & @CRLF) EndFunc Func ReadLine() Local Const $sFilePath = $g_sPath & "\line.txt" ;Open the file for reading and store the handle to a variable. Local $hFileOpen = FileOpen($sFilePath, $FO_READ) If $hFileOpen = -1 Then MsgBox(0, "", "An error occurred when reading the file.") Return False EndIf ;Read the fist line of the file using the handle returned by FileOpen. $sFileRead = FileReadLine($hFileOpen, 1) ;Close the handle returned by FileOpen. FileClose($hFileOpen) ;Display the first line of the file. ;MsgBox($MB_SYSTEMMODAL, "", $sFileRead) EndFunc ;https://www.autoitscript.com/forum/topic/135203-call-another-script/?do=findComment&comment=943199 ;guinness Func _RunAU3($sFilePath, $sParamet="", $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0) Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '" "' & $sParamet & '"', $sWorkingDir, $iShowFlag, $iOptFlag) ;Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"' & ' "Bos Días"', $sWorkingDir, $iShowFlag, $iOptFlag) EndFunc ;==>_RunAU3 UPDATE: I'm finally using a slightly different version of the 'Main' script. It seems more simple: without the boolean variable: #pragma compile(AutoItExecuteAllowed, True) ;#pragma compile(Icon, local_gray.ico) #include <WinAPIEx.au3> #include <Misc.au3> If _Singleton("test", 1) = 0 Then Msgbox(48,"Warning","already running." & @LF & "This instance will close.", 5) Exit EndIf OnAutoItExitRegister("OnAutoItExit") Global $g_sPath, $sFileRead, $aArray, $iID $g_sPath = "C:\Documents and Settings\XP\Escritorio\InterPC\bridge" Global $hDir = _WinAPI_FindFirstChangeNotification($g_sPath, $FILE_NOTIFY_CHANGE_LAST_WRITE) While 1 Sleep(500) CheckFile() WEnd Func CheckFile() $iID = _WinAPI_WaitForSingleObject($hDir, 0) If $iID = 0 Then ; WAIT_OBJECT_0 ;ConsoleWrite('A file was changed in the directory.' & @CRLF) Local $sFilePath = $g_sPath & "\line.txt" ;Open the file for reading and store the handle to a variable. Local $hFileOpen = FileOpen($sFilePath, $FO_READ) If $hFileOpen = -1 Then MsgBox(0, "", "An error occurred when reading the file.") Return False EndIf ;Read the fist line of the file using the handle returned by FileOpen. $sFileRead = FileReadLine($hFileOpen, 1) ;Close the handle returned by FileOpen. FileClose($hFileOpen) ;_RunAU3(".\scripts\AU3_Example.au3", $sFileRead, @ScriptDir, @SW_SHOW, 8) ;in $sFileRead there is a string with this format: AU3_Example.au3|parameter1 'parameter 2' ""parameter 3"" $aArray = StringSplit($sFileRead, "|") _RunAU3(".\scripts\" & $aArray[1], $aArray[2], @ScriptDir, @SW_SHOW, 8) ;SoundPlay(@WindowsDir & "\media\tada.wav", 0) ; Chimes.wav EndIf If Not _WinAPI_FindNextChangeNotification($hDir) Then MsgBox(48, 'Error', 'Bridge folder not found: revise settings.ini') Exit EndIf EndFunc ;https://www.autoitscript.com/forum/topic/135203-call-another-script/?do=findComment&comment=943199 ;guinness Func _RunAU3($sFilePath, $sParamet="", $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0) Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '" "' & $sParamet & '"', $sWorkingDir, $iShowFlag, $iOptFlag) ;Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"' & ' "Bos Días"', $sWorkingDir, $iShowFlag, $iOptFlag) EndFunc ;==>_RunAU3 Func OnAutoItExit() _WinAPI_FindCloseChangeNotification($hDir) EndFunc 'bridge' is the folder being monitored, and 'scripts' is another folder containing the scripts to execute when a change is detected Here an example in the scripts folder: AU3_Example.au3 MsgBox(0, "It Works", "Hello World, " & $CmdLine[1]) ConsoleWrite("Hello World from ConsoleWrite!, " & $CmdLine[1]) This is an example of an UPDATE statement with a MS ACCESS database in the server computer using the ADODB command method ;Help: COM Error Handling Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") If $CmdLine[0] = 0 Then Exit ;there is no parameter passed to the executable Local $sFilename = "_____" Global Const $iCursorType = 0 ; adOpenForwardOnly Global Const $iLockType = 1 ;1 adLockReadOnly, 3 adLockOptimistic Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable Global $cn = ObjCreate("ADODB.Connection") ; Create a connection object ;Global $sADOConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $sFilename Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilename & ";Jet OLEDB:Database Password=___;" $cn.Open($sADOConnectionString) ; Open the connection Global $cmd = ObjCreate("ADODB.Command") $cmd.ActiveConnection = $cn Global $sSQL = $CmdLine[1] $cmd.CommandText = $sSQL $cmd.CommandType = 1 ;adCmdText ;https://www.w3schools.com/asp/ado_ref_command.asp ;https://www.autoitscript.com/forum/topic/80351-adodb-command-method/ $cmd.Execute(Default,Default, 0x80) $cmd = 0 $cn.Close ; Close the connection $cn = 0 ; Release the connection object Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext _ ) Local $err = $errADODB.number If $err = 0 Then $err = -1 EndFunc An example of a SELECT query, saving the recordset as xml in a shared folder ;Help: COM Error Handling Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") If $CmdLine[0] = 0 Then Exit ;there is no parameter passed to the executable Local $sFilename = "_somepath_\MyDataBase.mdb" Local $sFilename2 = "_somepath_\InterPC\out\example.xml" FileDelete($sFilename2) Global Const $iCursorType = 0 ; adOpenForwardOnly Global Const $iLockType = 1 ;1 adLockReadOnly, 3 adLockOptimistic Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable Global $cn = ObjCreate("ADODB.Connection") ; Create a connection object Global $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object ;Global $sADOConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $sFilename Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilename & ";Jet OLEDB:Database Password=__;Mode=Read" $cn.Open($sADOConnectionString) ; Open the connection Local $sSQL = "SELECT ____" _ & " FROM __" _ & " WHERE " & $CmdLine[1] _ & " ORDER BY __;" $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ; Issue the SQL query $rst.Save($sFilename2, 1) $rst.Close $rst = 0 ; Release the recordset object $cn.Close ; Close the connection $cn = 0 ; Release the connection object Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext _ ) Local $err = $errADODB.number If $err = 0 Then $err = -1 EndFunc Finally an example of an INSERT query: ;Help: COM Error Handling Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") If $CmdLine[0] = 0 Then Exit ;there is no parameter passed to the executable Local $aArray $aArray = StringSplit($CmdLine[1], Chr(1)) Local $sSQL, $IdCab, $sYear $sYear = @YEAR Global Const $iCursorType = 0 ; adOpenForwardOnly, 3 adOpenStatic Global Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable Global $cn = ObjCreate("ADODB.Connection") ; Create a connection object Global $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object ;Global $sADOConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $sFilename ;Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilename & ";Jet OLEDB:Database Password=__" $cn.CursorLocation = 3 ; adUseClient $cn.Open($aArray[1]) ; Open the connection ;this ok ;$sSQL = "CREATE TABLE AutoIncrementTest " _ ; & "(ID int identity, Description varchar(40), " _ ; & "CONSTRAINT AutoIncrementTest_PrimaryKey PRIMARY KEY (ID))" ;$cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 ;this ok ;Global $cmd = ObjCreate("ADODB.Command") ;$cmd.ActiveConnection = $cn ;$cmd.CommandText = $sSQL ;$cmd.CommandType = 1 ;adCmdText ;https://www.w3schools.com/asp/ado_ref_command.asp ;https://www.autoitscript.com/forum/topic/80351-adodb-command-method/ ;$cmd.Execute(Default,Default, 1 + 0x80) $sSQL = "SELECT MAX(Val(SOMEFIELD)) FROM SOMETABLE" $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ; Issue the SQL query Local $CodAlb = StringFormat("%06i", $rst(0).Value + 1) ;MsgBox(0,"","New code Nº: " & $CodAlb) $rst.Close ;$sSQL = "SELECT ID, Description FROM AutoIncrementTest" $sSQL = "SELECT ID, YEAR, FIELD2, FIELD3, ____________ FROM MYTABLE" $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ; Issue the SQL query $cn.BeginTrans $rst.AddNew ;$rst("Description").Value = "AutoIncrement Test" ;$rst.Fields("Description") = "AutoIncrement Test" $rst("YEAR").Value = $sYear $rst("CODIGO").Value = $CodAlb $rst("FIELD2").Value = $aArray[2] $rst("FIELD3").Value = $aArray[5] ;... $rst.Update $IdCab = $rst(0).Value ;MsgBox(0,"","New Auto-increment value is: " & $IdCab) $rst.Close $sSQL = "UPDATE OTHERTABLE SET SOMEFIELD = " & $aArray[15] & " WHERE LINEASPEDIDO.ID = " & $aArray[14] $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 $cn.CommitTrans ;$cmd = 0 $rst = 0 ; Release the recordset object $cn.Close ; Close the connection $cn = 0 ; Release the connection object Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext _ ) Local $err = $errADODB.number If $err = 0 Then $err = -1 EndFunc
×
×
  • Create New...