Solved

300 Pts: List of Locked files in C#

Posted on 2006-07-24
21
905 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
ID: 17167623
0
 
LVL 1

Author Comment

by:hangar18
ID: 17169419
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
ID: 17169527
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:hangar18
ID: 17169632
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
ID: 17171101
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
ID: 17171249
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
ID: 17171301
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
ID: 17171367
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
ID: 17171500
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
 
LVL 41

Accepted Solution

by:
graye earned 300 total points
ID: 17172428
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
ID: 17371362
Pls close the question. I am still looking for an answer. What about the all the points..?
0
 
LVL 20

Expert Comment

by:Venabili
ID: 17371375
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
ID: 17371389
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
ID: 17371402
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
ID: 17371408
all apologies ..  been struck up here on other issues .. just getting back to these old ones!
0
 
LVL 20

Expert Comment

by:Venabili
ID: 17403772
Any update here?
0
 
LVL 1

Author Comment

by:hangar18
ID: 17405293
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
ID: 17541589
And this is abandoned again
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…

777 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