Solved

Help with _newenum

Posted on 2001-06-07
4
698 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

623 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