Solved

Help with _newenum

Posted on 2001-06-07
4
683 Views
Last Modified: 2007-11-27
I am trying to enum the virtual webservers in the iiswebservice object. Basically (for each website in webservice) in VB. I am trying to do this in Delphi 5.

WebSite := CreateOleObject('IISNamespace');
        WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc');
        Enum := website._newenumm as ienumvariant;

I can not get this to work. I was hoping someone here could shed some light.

Thanks in advance.
John Lindsly
0
Comment
Question by:jtl12
  • 2
4 Comments
 
LVL 6

Expert Comment

by:edey
ID: 6164553
I found this article: http://www.techvanguards.com/com/tutorials/tips.asp#Know%20how%20to%20implement%20clients%20that%20iterate%20IEnumVARIANT-based%20collections

Here's a snippet:

uses ComLib;

var
  Foo : IFoo;
  Item : olevariant;
  Enum : TEnumVariant;
begin
  Foo := CreateOleObject ('FooServer.Foo') as IFoo;  //or CoFoo.Create
  Enum := TEnumVariant.Create (Foo.Items);
  while (Enum.ForEach (Item)) do
    DoSomething (Item);
  Enum.Free;
end;

Note, I'm not sure what is contained in ComLib, but it's available (freely) from the authors website (see the above link).

GL
Mike
0
 

Author Comment

by:jtl12
ID: 6164572
Yea I have this code snippet. However iiswebservice does not appear to have an items prop. So I do not know how to apply this to my case.

Thanks for your help though
0
 
LVL 6

Expert Comment

by:edey
ID: 6164930
Hi, i really wish I could give more specific help, but i don't have IIS. At any rate I did find the following from a usenet article:

procedure TMainForm.btnListClick(Sender: TObject);
var
  ADsContainer: IADsContainer;
  EnumVariant : IEnumVariant;
  Child       : OleVariant;
  Fetched     : LongWord;
  ADSIPath    : WideString;
begin
  Lst.Clear;

  ADSIPath := 'IIS://localhost/W3SVC/1/ROOT';
  OleCheck(ADsGetObject(PWideChar(ADSIPath), IADsContainer, ADsContainer));

  // A Delphi For Each loop!
  EnumVariant := ADsContainer._NewEnum as IEnumVariant;
  EnumVariant.Reset;
  Fetched := 0;
  while Succeeded(EnumVariant.Next(1, Child, Fetched)) and (Fetched > 0) do
    Lst.Items.Add(Child.Name);
end;


perhaps it may shed some light on the issue.

GL
Mike
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 100 total points
ID: 6165120

I did not forget you from yesterday, I just didn't have the free until now.

So....

const
  IID_IADSContainer:   TGUID =  '{001677D0-FD16-11CE-ABC4-02608C9E7553}';

type
  IADSContainer  =  interface(IDispatch)
     ['{001677D0-FD16-11CE-ABC4-02608C9E7553}']
     function    get_Count(out plCount: Longint): HResult; stdcall;
     function    get__NewEnum(out ppEnumerator: IEnumVariant): HResult; stdcall;
     function    get_Filter(const pvFilter: Variant): HResult; stdcall;
     function    put_Filter(out pvFilter: Variant): HResult; stdcall;
     function    get_Hints(const pvHints: Variant): HResult; stdcall;
     function    put_Hints(out pvHints: Variant): HResult; stdcall;
     function    GetObject(const bstrClass, bstrRelativeName: WideString; out ppNamedObject: IDispatch): HResult; stdcall;
     function    Create(const bstrClass, bstrRelativeName: WideString; out ppNamedObject: IDispatch): HResult; stdcall;
     function    Delete(const bstrClass, bstrRelativeName: WideString): HResult; stdcall;
     function    CopyHere(const bstrSource, bstrNew: WideString; out ppNamedObject: IDispatch): HResult; stdcall;
     function    MoveHere(const bstrSource, bstrNew: WideString; out ppNamedObject: IDispatch): HResult; stdcall;
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var  oNameSpace: OleVariant;
     piac:       IADSContainer;
     oService:   OleVariant;
     oSite:      OleVariant;
     oServer:    OleVariant;
     oBindings:  OleVariant;
     oComputer:  OleVariant;
     pev:        IEnumVariant;
     s:          String;
begin

  CoInitialize(nil);

  oNameSpace:=CreateOleObject('IISNamespace');
  oService:=oNameSpace.GetObject('IIsWebService', 'localhost/w3svc');
  IDispatch(oService).QueryInterface(IADSContainer, piac);
  if piac.get__NewEnum(pev) = S_OK then
  begin
     pev.Reset;
     while pev.Next(1, oServer, nil) = S_OK do
     begin
        s:=oServer.Class;
        if CompareText(s, 'IIsWebServer') = 0 then
        begin
           // Check the server comment to the name
           // your looking for, like "Default Web Site"
           ShowMessage(oServer.ServerComment);
        end;
     end;
  end;

end;
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

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

20 Experts available now in Live!

Get 1:1 Help Now