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# ?

LVL 1
hangar18Asked:
Who is Participating?
 
grayeCommented:
Remember that the WinNT provider for ADSI only uses the old-style NetBIOS names... like SEVER01 not Server1.SomeDomain.com

Secondly, the IIS account is a highly-specialized account that designed to minimize the risk of intrusions... so I'd suggest that you try the code with a normal WinForm application first (as a test) while logged in as an administrator.  If that works, then we can adjust the impersonation to use a different account.
0
 
hangar18Author Commented:
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?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
grayeCommented:
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).
0
 
hangar18Author Commented:
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?
0
 
grayeCommented:
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?
0
 
hangar18Author Commented:
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..
0
 
grayeCommented:
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".
0
 
hangar18Author Commented:
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?
0
 
hangar18Author Commented:
Actually we tried net start LanmanServer and it says the service is already running. But we still cannot access the Lanmanserver through ADSI... help!!
0
 
hangar18Author Commented:
Pls close the question. I am still looking for an answer. What about the all the points..?
0
 
VenabiliCommented:
An expert posted a comment. You IGNORED it.

How someone would know that you still need help?
What is wrong with the last suggestion?
0
 
hangar18Author Commented:
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..
0
 
VenabiliCommented:
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...
0
 
hangar18Author Commented:
all apologies ..  been struck up here on other issues .. just getting back to these old ones!
0
 
VenabiliCommented:
Any update here?
0
 
hangar18Author Commented:
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 ..
0
 
VenabiliCommented:
And this is abandoned again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.