Solved

How to use ADSI to get list of open files on share

Posted on 2004-09-01
3
850 Views
Last Modified: 2010-04-05
I'm trying to use ADSI to get a list of open files on a share. I've mimicked how to successfully do it in VBS, except when I do it in Delphi, I get a list of the shares, rather than the open files.

For example:

  VBSCRIPT:
-----------------------------------------------------
'  Bind to a file service operations object on “servername" in the local domain.
Set fso = GetObject("WinNT://<servername>/LanmanServer")

' Enumerate resources
If (IsEmpty(fso) = False) Then
For Each resource In fso.resources
 
  ' Add Item to some list
Next
End If
------------------------------------------------------

Now in Delphi I tried doing to same thing:

Dephi:
-----------------------------------------------------

hr := ADsGetObject('WinNT://<servername>/Lanmanserver',IADsContainer,Container);
  if Failed(hr) then exit;

  hr := ADsBuildEnumerator(Container,e);  // start enumerating
  while SUCCEEDED(hr) do
  begin
    // get the next contained object
    hr := ADsEnumerateNext(e,1,varArr,lNumElements);
    if (lNumElements<=0) then
      break;

    IDispatch(varArr).QueryInterface(IADs, item) ;
    ListBox1.AddItem(item.ADsPath,nil);
 end;

------------------------------------------------------  

The VBScript seems to return the names of files and folders open on the share, however the delphi code returns the actual shares themselves, with no mention of the files opened. Anyone know what I have to do to get the delphi code to return the actual files?
0
Comment
Question by:stauffec
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 275 total points
ID: 11961419
The VB Script is calling a method called resources. It's actually enumerating the Resources property, not the container itself. (At least, if I'm not mistaken.) The only ADSI component that has Resources is the IADsFileServiceOperations property so I think you need to use:

var Container: IADsFileServiceOperations;
begin
  hr := ADsGetObject('WinNT://<servername>/Lanmanserver',IADsFileServiceOperations,Container);

instead. But this is a bit of a wild guess. I can't test this right now.The Resources is an IADsCollection type which you can enumerate again, btw.
0
 

Author Comment

by:stauffec
ID: 11962187
I'm going to give it a try here - i'll let you know. I thought it might have something to do with that.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11997099
And? Is your problem solved?
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

22 Experts available now in Live!

Get 1:1 Help Now