Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with _newenum

Posted on 2001-06-07
4
Medium Priority
?
706 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 400 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

926 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