Solved

300 Pts: List of Locked files in C#

Posted on 2006-07-24
21
877 Views
Last Modified: 2008-01-09
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# ?

0
Comment
Question by:hangar18
  • 9
  • 5
  • 4
21 Comments
 
LVL 41

Expert Comment

by:graye
Comment Utility
0
 
LVL 1

Author Comment

by:hangar18
Comment Utility
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
 
LVL 41

Expert Comment

by:graye
Comment Utility
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
 
LVL 1

Author Comment

by:hangar18
Comment Utility
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
 
LVL 41

Expert Comment

by:graye
Comment Utility
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
 
LVL 1

Author Comment

by:hangar18
Comment Utility
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
 
LVL 41

Expert Comment

by:graye
Comment Utility
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
 
LVL 1

Author Comment

by:hangar18
Comment Utility
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
 
LVL 1

Author Comment

by:hangar18
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 41

Accepted Solution

by:
graye earned 300 total points
Comment Utility
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
 
LVL 1

Author Comment

by:hangar18
Comment Utility
Pls close the question. I am still looking for an answer. What about the all the points..?
0
 
LVL 20

Expert Comment

by:Venabili
Comment Utility
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
 
LVL 1

Author Comment

by:hangar18
Comment Utility
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
 
LVL 20

Expert Comment

by:Venabili
Comment Utility
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
 
LVL 1

Author Comment

by:hangar18
Comment Utility
all apologies ..  been struck up here on other issues .. just getting back to these old ones!
0
 
LVL 20

Expert Comment

by:Venabili
Comment Utility
Any update here?
0
 
LVL 1

Author Comment

by:hangar18
Comment Utility
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
 
LVL 20

Expert Comment

by:Venabili
Comment Utility
And this is abandoned again
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now