Solved

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

Posted on 2004-09-01
3
875 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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