Sign in to follow this  
Followers 0
myspacee

Understand if a file is open/in use/in handle ?

3 posts in this topic

hello,

made a script that rename a large amount of files,

but want undertand if a file is open/in use/handled by

a process before interact with him ... is possible ?

thank you all,

m.

Share this post


Link to post
Share on other sites



hello,

made a script that rename a large amount of files,

but want undertand if a file is open/in use/handled by

a process before interact with him ... is possible ?

thank you all,

m.

This is an example by Siao.

;~ by Siao
Global Const $GENERIC_READ  = 0x80000000
Global Const $GENERIC_WRITE = 0x40000000
Global Const $OPEN_EXISTING = 3
Global Const $FILE_ATTRIBUTE_NORMAL = 0x80

$file = "d:\Base\work.dat"
If Not FileExists($file) Then Exit

$hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", _
                  "str", $file, _
                  "int", BitOR($GENERIC_READ, $GENERIC_WRITE), _
                  "int", 0, _
                  "ptr", 0, _
                  "int", $OPEN_EXISTING, _
                  "int", $FILE_ATTRIBUTE_NORMAL, _
                  "int", 0)

If $hFile[0] = -1 Then
    MsgBox(48, "Warning", "File is open")
Else
    DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile[0])
EndIf

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Do somebody know this if this example work on network (administrative shares)?

Thanks in advance

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  
Followers 0