Solved

Help with _newenum

Posted on 2001-06-07
4
686 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

806 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