Prüfen ob eine Datei geöffnet ist

  • So wie ich es verstanden hab möchtest du testen ob etwas bereits läuft, dafür solltest du dir

    [autoit]

    ProcessExists()

    [/autoit]

    anschauen. Mit dem was Prajoss gesagt hat, kannst du überprüfen ob du ein Programm erfolgreich geöffnet hast (also mit dem Script), aber nicht ob es bereits läuft.

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake

  • Spoiler anzeigen
    [autoit]

    ;===============================================================================
    ;
    ; Function Name: _FileInUse()
    ; Description: Checks if file is in use
    ; Syntax.........: _FileInUse($sFilename, $iAccess = 1)
    ; Parameter(s): $sFilename = File name
    ; Parameter(s): $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode
    ; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file,
    ; fails if file open in readonly mode by app
    ; Return Value(s): 1 - file in use (@error contains system error code)
    ; 0 - file not in use
    ; -1 dllcall error (@error contains dllcall error code)
    ; Author: Siao
    ; Modified rover - added some additional error handling, access mode
    ; Remarks _WinAPI_CreateFile() WinAPI.au3
    ;===============================================================================
    Func _FileInUse($sFilename, $iAccess = 0)
    Local $aRet, $hFile, $iError, $iDA
    Local Const $GENERIC_WRITE = 0x40000000
    Local Const $GENERIC_READ = 0x80000000
    Local Const $FILE_ATTRIBUTE_NORMAL = 0x80
    Local Const $OPEN_EXISTING = 3
    $iDA = $GENERIC_READ
    If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE)
    $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _
    "str", $sFilename, _ ;lpFileName
    "dword", $iDA, _ ;dwDesiredAccess
    "dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE
    "dword", 0x00000000, _ ;lpSecurityAttributes = NULL
    "dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING
    "dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL
    "hwnd", 0) ;hTemplateFile = NULL
    $iError = @error
    If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1)
    $hFile = $aRet[0]
    If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1
    $aRet = DllCall("Kernel32.dll", "int", "GetLastError")
    ;ERROR_SHARING_VIOLATION = 32 0x20
    ;The process cannot access the file because it is being used by another process.
    If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1)
    Return SetError($aRet[0], 0, 1)
    Else
    ;close file handle
    DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
    Return SetError(@error, 0, 0)
    EndIf
    EndFunc

    [/autoit]
  • Geöffnete Dateien werden ja unter Computer Verwaltung (Freigaben/Geöffnete Dateien) gelistet,
    ich weiß nur nicht wo das in der Registry o.ä. zu finden ist.
    Obwohl das meine ich nur remote geöffnete zeigt?

    Achtung Anfänger! :whistling:

    Betrachten des Quellcodes auf eigene Gefahr, bei Übelkeit,Erbrechen,Kopfschmerzen übernehme ich keine Haftung. 8o