Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locked File's Owner...

Status
Not open for further replies.

devilman0

IS-IT--Management
Nov 14, 2002
257
US
I'm trying to figure out how to determing the owner (exe or name) of a file (txt or binary) that is locked. I've googled and googled and searched on here for some code that'll show me how to do this, but have come up blank (maybe wrong search string.)

I've seen an app that does this, wholockme? and it works well, however, I would like to include this in my program so I can give a description of the problem to the user, not just the file was locked, but by whom. I'm thinking this can be done via api, but don't see anything obvious.

TIA

Thanks,
James
[afro][mad]
"Make it idiot-proof and someone will make a better idiot." ~bumper sticker
 
You can use this code as a start. I am sure it can be modified a great deal for efficiency...

You'll need a reference to the Active DS Type Library. If you don't want to include the reference, you should be able to late bind without any problems.
Code:
Option Explicit
Private Sub Form_Load()
    Dim Server As String
    Dim objFSOps As IADsFileServiceOperations
    Dim objResource As IADsResource
    Dim FindPos As Long
    
    Server = "crpwdevtest"
        
    On Error Resume Next
    
    Set objFSOps = GetObject("WinNT://" & Server & "/LanmanServer")
    
    If IsEmpty(objFSOps) = False Then
        For Each objResource In objFSOps.Resources
            If (Not objResource.User = "") And (Not Right(objResource.User, 1) = "$") Then  'Check for user be empty
                Debug.Print objResource.User & " --- " & objResource.Path
            End If
        Next
    End If
End Sub
 
Hmm,
That looks good, when you have people sharing. I guess I wasn't totaly clear. Owner = Application, and this will just be checking local files. IE, word.exe is locking my_word_doc.doc (i would query my_word_doc.doc and it would give either a name or handle (doesn't matter))

bjd4jc, Thank you for your post :)

Thanks,
James
[afro][mad]
"Make it idiot-proof and someone will make a better idiot." ~bumper sticker
 
For the server name just enter the name of the local computer.... that is if they're running NT4 or higher.
 
Maybe I'm not calling what I'm looking for the correct thing, so I'll try to re-explain:
I have a program that tries to access a file for write, however, I get file locked error, so, in order to write I have to keep trying to write. What I was looking for was the PROGRAM (not user, not person, nor through the network) that is locking the file on the LOCAL machine. A program called wholocksme? does exactly what I'm looking to try and do. I am not concerned with the owner, security, or any thing related to USER all i'm looking for is the APPLICATION or PROGRAM that is locking the file.

Tx for all your post thus far.


Thanks,
James
[afro][mad]
"Make it idiot-proof and someone will make a better idiot." ~bumper sticker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top