Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 189
Send message from delphi to whatsapp, is it possible? 3 1,143
Base1 Encode/Decode 3 67
Delphi...Split view - idea? 1 40
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A short film showing how OnPage and Connectwise integration works.

932 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

12 Experts available now in Live!

Get 1:1 Help Now