Information ausgeben wenn neue Datei erstellt wird.

  • Hallo AutoIt Community,

    ich würde gerne wissen ob es möglich ist mit Autoit zu erkennen ob eine neue Datei auf einem Computer erstellt wurde.

    Beispiel:
    -> (User) läd eine Datei aus dem Internet runter.
    -> (Script) bemerkt die neue Datei und gibt den Pfad aus.


    Geht sowas mit AutoIt ?

    Grüße
    derBrot

  • Beispielsweise könntest du die Windows Fenster erkennen und dementsprechend das Programm darauf achten lassen ob der User die Datei speichert.
    Oder direkt einfach jede Aktion des Users überwachen und darauf achten ob irgendwas mit Dateien geschieht.

    Oder du erstellst eine gesamte Liste von allen Datein auf dem Rechner und lässt diese immer wieder überprüfen und reagierst auf änderungen.
    Ist aber ziemelich Zeitaufwendig. Je nachdem ob du alle Ordner durchsuchen willst...

    Spontan fällt mir nichts weiteres ein.

  • Sofern man es nichtmal auf einen Ordner eingrenzen kann wäre das ziemlich ineffizient die komplette Festplatte durch Rekursive Dateisuche zu vergleichen. Auch die Überwachung von irgendwelchen Fenstern ist eher weniger zielführend, dazu gibt es vielzuviele Möglichkeiten wie eine Datei auf einer Festplatte landen kann, teilweise sogar ohne irgendwelche Fenster die man abfangen könnte. Ich empfehle daher einen Blick auf den Beitrag von Aspirinjunkie:

    https://autoit.de/index.php?page…7614#post267614

    Prinzipiell sollte es ausreichen die Switch Case Verzeweigung in EvaluateEvents() anzupassen, damit man nicht mehr über Dateiveränderungen sondern Dateierstellungen informiert wird. Außerdem natürlich die richtige Konstante verwenden um das zu überwachende Event mit RegisterFSEvent() zu registrieren.

  • misterspeed Danke für die Antwort :)

    @m-obi Ich würde aber gerne das sich das script auf den kompletten PC bezieht.

    Hier mein versuch, hat aber jedoch nicht funktioniert :o

    [autoit]


    #include <WinAPI.au3>

    [/autoit][autoit][/autoit][autoit]

    Opt("TrayAutoPause", 0)

    [/autoit][autoit][/autoit][autoit]

    Global Const $SHCNE_RENAMEITEM = 0x0001
    Global Const $SHCNE_CREATE = 0x0002
    Global Const $SHCNE_DELETE = 0x0004
    Global Const $SHCNE_MKDIR = 0x0008
    Global Const $SHCNE_RMDIR = 0x0010
    Global Const $SHCNE_UPDATEDIR = 0x1000
    Global Const $SHCNE_UPDATEITEM = 0x2000
    Global Const $SHCNE_UPDATEIMAGE = 0x8000
    Global Const $SHCNE_RENAMEFOLDER = 0x20000
    Global Const $SHCNE_ALLEVENTS = 0x7FFFFFFF

    [/autoit][autoit][/autoit][autoit]

    OnAutoItExitRegister("OnAutoItExit")

    [/autoit][autoit][/autoit][autoit]

    $SHNOTIFY = _WinAPI_RegisterWindowMessage("shchangenotifymsg")

    [/autoit][autoit][/autoit][autoit]

    $gui = GUICreate("")
    GUIRegisterMsg($SHNOTIFY, "MY_SHNOTIFY")

    [/autoit][autoit][/autoit][autoit]

    ;~ If Not FileExists("C:\test") Then DirCreate("C:\test")
    ;~ If Not FileExists("C:\test2") Then DirCreate("C:\test2")
    $ppidl = DllCall("shell32.dll", "ptr", "ILCreateFromPathW", "wstr", "C:\")
    ConsoleWrite($ppidl[0] & @CRLF)
    $ppidl2 = DllCall("shell32.dll", "ptr", "ILCreateFromPathW", "wstr", "C:\")
    ConsoleWrite($ppidl2[0] & @CRLF)
    $shArray = DllStructCreate("double; double"); 16 bytes = two 8 byte shnotifystructs in an array
    ; == this could also be done as DllStructCreate("double[2]"), $pshArray = DllStructGetPtr($shArray)
    ; == then below would be
    ; == $shnotifystruct = DllStructCreate("ptr pidl; int fRecursive", $pshArray)
    ; == $shnotifystruct2 = DllStructCreate("ptr pidl; int fRecursive", $pshArray + 8) -> ptr to array plus 8 bytes
    ; == for many folders, either method could be achieved by use of loops
    $shnotifystruct = DllStructCreate("ptr pidl; int fRecursive", DllStructGetPtr($shArray, 1)); first struct, first element
    ConsoleWrite("error1: " & @error & @CRLF)
    DllStructSetData($shnotifystruct, "pidl", $ppidl[0])
    DllStructSetData($shnotifystruct, "fRecursive", 0)
    $shnotifystruct2 = DllStructCreate("ptr pidl; int fRecursive", DllStructGetPtr($shArray, 2)); second struct, second element
    ConsoleWrite("error2: " & @error & @CRLF)
    DllStructSetData($shnotifystruct2, "pidl", $ppidl2[0])
    DllStructSetData($shnotifystruct2, "fRecursive", 0)
    $register = DllCall("shell32.dll", "int", "SHChangeNotifyRegister", "hwnd", $gui, _
    "int", 0x0003, _
    "long", BitOR($SHCNE_CREATE, $SHCNE_DELETE, $SHCNE_MKDIR, $SHCNE_RMDIR), _
    "uint", $SHNOTIFY, _
    "int", 2, _; number of shnotifystructs in the array
    "ptr", DllStructGetPtr($shArray)); ptr to the array
    ; free each created PIDL
    DllCall("ole32.dll", "none", "CoTaskMemFree", "ptr", $ppidl[0])
    DllCall("ole32.dll", "none", "CoTaskMemFree", "ptr", $ppidl2[0])
    $shArray = 0
    $shnotifystruct = 0
    $shnotifystruct2 = 0
    ConsoleWrite("register: " & $register[0] & @CRLF)

    [/autoit][autoit][/autoit][autoit]

    While 1
    Sleep(1000)
    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func OnAutoItExit()
    ; deregister the window
    $ret = DllCall("shell32.dll", "int", "SHChangeNotifyDeregister", "ulong", $register[0])
    ConsoleWrite("deregister: " & $ret[0] & @CRLF)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func MY_SHNOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $path

    [/autoit][autoit][/autoit][autoit]

    ConsoleWrite("notify: " & $lParam & @CRLF)
    $path = DllStructCreate("dword dwItem1; dword dwItem2", $wParam)
    $ret = DllCall("shell32.dll", "int", "SHGetPathFromIDListW", "ptr", DllStructGetData($path, "dwItem1"), "wstr", "")
    ConsoleWrite($ret[2] & @CRLF)
    EndFunc

    [/autoit]
  • Ich hab es so. Mit $SHCNE_ALLEVENTS.

    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("TrayAutoPause", 0)

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $SHCNE_RENAMEITEM = 0x0001
    Global Const $SHCNE_CREATE = 0x0002
    Global Const $SHCNE_DELETE = 0x0004
    Global Const $SHCNE_MKDIR = 0x0008
    Global Const $SHCNE_RMDIR = 0x0010
    Global Const $SHCNE_UPDATEDIR = 0x1000
    Global Const $SHCNE_UPDATEITEM = 0x2000
    Global Const $SHCNE_UPDATEIMAGE = 0x8000
    Global Const $SHCNE_RENAMEFOLDER = 0x20000
    Global Const $SHCNE_ALLEVENTS = 0x7FFFFFFF

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("OnAutoItExit")

    [/autoit] [autoit][/autoit] [autoit]

    $SHNOTIFY = _WinAPI_RegisterWindowMessage("shchangenotifymsg")

    [/autoit] [autoit][/autoit] [autoit]

    $gui = GUICreate("")
    GUIRegisterMsg($SHNOTIFY, "MY_SHNOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ;~ If Not FileExists("C:\test") Then DirCreate("C:\test")
    ;~ If Not FileExists("C:\test2") Then DirCreate("C:\test2")
    $ppidl = DllCall("shell32.dll", "ptr", "ILCreateFromPathW", "wstr", "C:\test")
    ConsoleWrite($ppidl[0] & @CRLF)
    $ppidl2 = DllCall("shell32.dll", "ptr", "ILCreateFromPathW", "wstr", "C:\test2")
    ConsoleWrite($ppidl2[0] & @CRLF)
    $shArray = DllStructCreate("double; double"); 16 bytes = two 8 byte shnotifystructs in an array
    ; == this could also be done as DllStructCreate("double[2]"), $pshArray = DllStructGetPtr($shArray)
    ; == then below would be
    ; == $shnotifystruct = DllStructCreate("ptr pidl; int fRecursive", $pshArray)
    ; == $shnotifystruct2 = DllStructCreate("ptr pidl; int fRecursive", $pshArray + 8) -> ptr to array plus 8 bytes
    ; == for many folders, either method could be achieved by use of loops
    $shnotifystruct = DllStructCreate("ptr pidl; int fRecursive", DllStructGetPtr($shArray, 1)); first struct, first element
    ConsoleWrite("error1: " & @error & @CRLF)
    DllStructSetData($shnotifystruct, "pidl", $ppidl[0])
    DllStructSetData($shnotifystruct, "fRecursive", 0)
    $shnotifystruct2 = DllStructCreate("ptr pidl; int fRecursive", DllStructGetPtr($shArray, 2)); second struct, second element
    ConsoleWrite("error2: " & @error & @CRLF)
    DllStructSetData($shnotifystruct2, "pidl", $ppidl2[0])
    DllStructSetData($shnotifystruct2, "fRecursive", 0)
    $register = DllCall("shell32.dll", "int", "SHChangeNotifyRegister", "hwnd", $gui, _
    "int", 0x0003, _
    "long", $SHCNE_ALLEVENTS, _
    "uint", $SHNOTIFY, _
    "int", 2, _; number of shnotifystructs in the array
    "ptr", DllStructGetPtr($shArray)); ptr to the array
    ; free each created PIDL
    DllCall("ole32.dll", "none", "CoTaskMemFree", "ptr", $ppidl[0])
    DllCall("ole32.dll", "none", "CoTaskMemFree", "ptr", $ppidl2[0])
    $shArray = 0
    $shnotifystruct = 0
    $shnotifystruct2 = 0
    ConsoleWrite("register: " & $register[0] & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(1000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func OnAutoItExit()
    ; deregister the window
    $ret = DllCall("shell32.dll", "int", "SHChangeNotifyDeregister", "ulong", $register[0])
    ConsoleWrite("deregister: " & $ret[0] & @CRLF)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func MY_SHNOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $path

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite("notify: " & $lParam & @CRLF)
    $path = DllStructCreate("dword dwItem1; dword dwItem2", $wParam)
    $ret = DllCall("shell32.dll", "int", "SHGetPathFromIDListW", "ptr", DllStructGetData($path, "dwItem1"), "wstr", "")
    ConsoleWrite($ret[2] & @CRLF)
    EndFunc

    [/autoit]


    Und das geht auf dem ganzen PC.

  • Wahrscheinlich kannst du ein hook erstellen auf die Windows Funktionen, die die Datei handeln. Aber ich bin nicht sicher, das AutoIt es tun kann. (Vielleicht wirst du C benutzten brauchen)

    Edit: hatte nicht den obenen Antwort gesehen