Solved

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

Posted on 2004-09-01
3
868 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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