Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

831 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