The reason I'm asking is because sometimes bugged (?)
applications fail to release their lock and the result is
a file you can (usually) only read from.
Or do I have to dig into the Win32 API's to do this? I
saw something about NetFileGetInfo but I was hoping for
a "cleaner" and easier way to do it... :-/
using System;
using System.DirectoryServices;
using activeds; // import activeds.tlb using tlbimp.exe
// List all File shares on a system only for W2K, XP and higher
class Tester {
public static void Main() {
// Bind using explict credentials
using(DirectoryEntry container = new DirectoryEntry("WinNT://<serverName>/LanmanServer", "domain\\someadmin", "adminpwd",
AuthenticationTypes.ServerBind))
{
foreach(DirectoryEntry share in container.Children)
{
PropertyCollection pcoll = share.Properties;
try
{
foreach(string sc in pcoll.PropertyNames) {
Console.WriteLine(sc + ":\t" + (pcoll[sc])[0].ToString());
// Show Session and Resource info, when user count > 0
if (sc == "CurrentUserCount" && (int)pcoll["CurrentUserCount"][0] > 0)
{
IADsFileServiceOperations fso = container.NativeObject as IADsFileServiceOperations;
Console.WriteLine("----- Session info -------");
foreach(IADsSession session in fso.Sessions())
{
Console.WriteLine("\tComputer: {0}", session.Computer);
Console.WriteLine("\tUser: {0}", session.User);
Console.WriteLine("\tConnect time: {0}", session.ConnectTime);
Console.WriteLine("\tIdle time: {0}", session.IdleTime);
Console.WriteLine("\tName: {0}", session.Name);
}
IADsCollection resources = fso.Resources() as IADsCollection;
Console.WriteLine("----- Resource info -------");
try {
foreach(IADsResource resource in resources)
{
Console.WriteLine("\tPath: {0}", resource.Path);
Console.WriteLine("\tUser: {0}", resource.User);
Console.WriteLine("\tLockCount: {0}", resource.LockCount);
Console.WriteLine("\tName: {0}", resource.Name);
Console.WriteLine("------------------------------");
}
}
catch (System.Runtime.InteropServices.COMException ex){
// Watch Non-Fileshare resources like named pipes, these are not stored in the ADSI cache
Console.WriteLine(ex.Message);
}
}
}
Console.WriteLine("---------------------------------");
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
}
Willy.
"Jonas Nordlund" <juga...@despammed.com> wrote in message news:1114301c25c02$6e781a50$37ef2ecf@TKMSFTNGXA13...