Link to home
Start Free TrialLog in
Avatar of hangar18
hangar18

asked on

300 Pts: List of Locked files in C#

Hi,
We would like to list the files that are locked by users and also the count of locks.
The existing code we have is something like this:

Set fso = GetObject("WinNT://" & strServer & "/LanmanServer")
For Each r in fso.Resources
      on error resume next
      rsNew.AddNew
      rsNew("Path") = r.Path
      rsNew("Name") = r.Name
      rsNew("LockCount") = r.LockCount
      rsNew("User") = r.User
      rsNew.UpdateBatch
    end if
  end if
Next


How do we do this in C# ?

Avatar of graye
graye
Flag of United States of America image

Avatar of hangar18
hangar18

ASKER

Thanks for the link.
we have implemented it and have a couple of queries.

THis is the output that we have got

ADS PAth    
CLass         Resource
Parent        
Name:         1692
Path:        D:\Websites\MyWebsite
User:        MyUserID
LockCount:     0
Schema       WinNT://DomainName/Schema/Resource

Here can you please etll us what this "Name" contains and why are we getting an integer value everytime?
And somehow the lock count does not seem to be working.
We tried opening a shared file in 2 other systems.

Are we missing something here?
Is this a web application?  

What do you get when you look at the "Shared Folder\Open Files" item the Computer Management MMC

There are two kinds of locking mechanisms used in Windows... one for network shares and one for the file system itself.   So, for example, if I have a file open and locked on my local PC, it will not show up in the "Shared Folders\Open Files" list.  This would also be true for ordinary web applications since the user doesn't have a process running on the server... instead everything is being run as the IIS account (and therefore local).
This is a web application but we are showing the list of shares on the network.
If we select a share, then we are supposed to display the list of files that are open and also display the number of users who have opened that file (Lock Count).
Will this code not work for this scenario? If not then any idea on how to proceed?
I don't see why it wouldn't work as a web application.... are the shares on the same server as the web server?

What about the answer to the previous question, on what do you see if you check the user/locks "manually" via the Shared Folders\Open Files?  Do you get the answer you were expecting?   Does it match what the program provides?
ok .. I'm not aware of how to do it manually..? pls let me know if u have an idea .. I may get some clues from that then..
on the server... right click on the "My Computer" icon, select the "Manage" menu item.   From there you drill down to "System Tools\Shared Folders\Open Files".
great got that ... thanks ..
one more question and then I think I can proceed ...
We are using Active Directory "WinNT://Server/LanmanServer" to loop through the resources adn get the lock count.
But out here we are getting the error that the service/workstation is not running (its giving some other error now so dont quite rememebr). Do you by any chance have any idea as to what I need to do to enable Lanman serer?
Actually we tried net start LanmanServer and it says the service is already running. But we still cannot access the Lanmanserver through ADSI... help!!
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pls close the question. I am still looking for an answer. What about the all the points..?
An expert posted a comment. You IGNORED it.

How someone would know that you still need help?
What is wrong with the last suggestion?
hmmm actually we are still working on it. Maybe once i get some more leads and then probably get back with more queries. Actually can we leave it open .. i'll have some queries in the next couple of days..
And you needed a month AND a reminder just to tell the expert that you work on this?
This is a collaborative site - you need to communicate. Additionally - all experts are volunteers and they deserve you to share what happens...
all apologies ..  been struck up here on other issues .. just getting back to these old ones!
Any update here?
not yet ..
apparently the code is just about working but I may need to look at seeing whether this is possible by invoking the Management console .. will keep you updated ..
And this is abandoned again