Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / January 2007

Tip: Looking for answers? Try searching our database.

C# equivilent to GetObject()?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Thielen - 29 Dec 2006 23:12 GMT
Hi;

How can I do the following in C# in all managed code:
Set IIsSmtpSvrObj = GetObject("IIS://localhost/SMTPSVC/1")

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

Willy Denoyette [MVP] - 30 Dec 2006 10:24 GMT
> Hi;
>
> How can I do the following in C# in all managed code:
> Set IIsSmtpSvrObj = GetObject("IIS://localhost/SMTPSVC/1")

The above is using GetObject to access the  ADSI IIS provider interface, you can achieve the
same from managed code by using the System.DirectoryServices wrapper classes like this:

DirectoryEntry entry = new DirectoryEntry (IIS://localhost/SMTPSVC/1);
...
Another (preferable) option is to use the System.Management namespace (WMI wrappers)
classes.

Check this:
http://msdn2.microsoft.com/en-us/library/aa155133.aspx
for details...

Willy.
David Thielen - 30 Dec 2006 19:33 GMT
I tried System.Management a buch of ways (last attempt below) but none
worked. Anyone know how to do this?

            ConnectionOptions con = new ConnectionOptions();

            ManagementPath path = new ManagementPath();
            path.Server = "localhost";
            path.NamespacePath = @"root\MicrosoftIISv2";
            path.RelativePath = "IIsWebService.Name='W3SVC'";

            ManagementScope session = new ManagementScope(path, con);
            session.Connect();

            ManagementPath p = new ManagementPath("IIsWebService");
IIsWebService.Name='SMTPSVC'
            ManagementClass webService = new ManagementClass(session, p, null);

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

> > Hi;
> >
[quoted text clipped - 14 lines]
>
> Willy.
Willy Denoyette [MVP] - 30 Dec 2006 20:57 GMT
>I tried System.Management a buch of ways (last attempt below) but none
> worked. Anyone know how to do this?
[quoted text clipped - 12 lines]
> IIsWebService.Name='SMTPSVC'
> ManagementClass webService = new ManagementClass(session, p, null);

Nothing of this all, you need to connect to the root\MicrosoftIISV2 WMI namespace, and get
the instance of the IIsSmtpDomainSetting class. RelayIpList is a property of this class, and
is of type uint[]

Following snip shows you how to retrieve the RelayIpList array from IIS Metadata using
System.Management and WMI.

   ...
 ManagementScope scope = new ManagementScope(@"\root\MicrosoftIISV2");
 string objPath = "IIsSmtpDomainSetting";
 using(ManagementClass mc = new ManagementClass(scope, new ManagementPath(objPath), null))
 {
           foreach (ManagementObject c in mc.GetInstances())
           {
               uint[] rIPList = c.Properties["RelayIpList"].Value as uint[];
               foreach( uint x in rIPList)
                   ...
           }
 }
 ...

All this and a lot more in the IIS Management SDK docs:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/643
6aeaf-d4c3-4e1f-8cd3-96359ff427ce.asp

David Thielen - 01 Jan 2007 01:23 GMT
Hi;

I've spent 45 minutes searching through the link you gave me and further in
with no luck. I'm hitting a problem that mc.GetInstances() is returning:
System.Management.ManagementException occurred
 Message="Invalid namespace "
 Source="System.Management"
 StackTrace:
      at System.Management.ManagementScope.Initialize()
      at System.Management.ManagementObject.Initialize(Boolean getObject)
      at System.Management.ManagementClass.GetInstances(EnumerationOptions
options)
      at System.Management.ManagementClass.GetInstances()
      at WindwardRePortalSystemSetup.Program.Main() in
C:\src\RePortal\WindwardRePortalSystemSetup\Program.cs:line 40

any ideas?

Also, the url you gave me says C# code should use System.DirectoryServices.
Is that left over from .NET 1.1 times?

And finally, this has to work on IIS 5 as well as IIS 6 as some of our
customers will be using W2K or WinXP. It looks like some (all?) of the WMI
API is limited to IIS 6.

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

> >I tried System.Management a buch of ways (last attempt below) but none
> > worked. Anyone know how to do this?
[quoted text clipped - 37 lines]
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/643
6aeaf-d4c3-4e1f-8cd3-96359ff427ce.asp
Willy Denoyette [MVP] - 02 Jan 2007 10:54 GMT
> Hi;
>
[quoted text clipped - 13 lines]
>
> any ideas?

What OS are you runing this on? Note that the WMI provider is not available on XP (IIS 5.1)
nor is the SMTP service, as such you won't find the IIsSmtpDomainSetting namespace.

> Also, the url you gave me says C# code should use System.DirectoryServices.
> Is that left over from .NET 1.1 times?

No it's not framework related,  the WMI provider needs IIS6 and higher, the ADSI provider is
usable for IIS5 and (limitted support) IIS6 (W2K3 SP1 and XP SP2).

> And finally, this has to work on IIS 5 as well as IIS 6 as some of our
> customers will be using W2K or WinXP. It looks like some (all?) of the WMI
> API is limited to IIS 6.

Full support for WMI is only available starting from IIS6, for lower versions you'll need
ADSI (System.DirectoryServices). Note also that W2K is end of life, and XP's IIS 5.1 doesn't
support all of IIS6 and higher functionality.
That's why I recommend the System.Management (WMI provider interface) namespace, ADSI is no
longer updated to support the latest IIS versions.

The IIS 6 WMI provider stuff is found here:
http://msdn2.microsoft.com/en-us/library/ms525265.aspx
While the ADSI stuff is here:
http://msdn2.microsoft.com/en-us/library/ms524997.aspx

Note that for all WMI provider interface testing you should use CIMstudio (part of the WMD
SDK) or wbemtest.exe, learn to use these tools before you even try to implement something in
code.

Willy.
David Thielen - 30 Dec 2006 19:43 GMT
Hi;

I also tried:
string name = "IIS://localhost/SMTPSVC/1";
DirectoryEntry entry = new DirectoryEntry (name);
PropertyValueCollection relayList = entry.Properties["RelayIpList"];
object obj = relayList[0];

And obj is a ComObject. What is this and how do I convert it into something
I can use?

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

> > Hi;
> >
[quoted text clipped - 14 lines]
>
> Willy.
Ben Voigt - 01 Jan 2007 17:16 GMT
> Hi;
>
[quoted text clipped - 7 lines]
> something
> I can use?

It's what it sounds like, a COM object with properties and fields and the
whole gamut.  If you just want the default value property, you can use
VarXYZFromDisp where XYZ is the appropriate numeric type like UI1 or I4 or
Bstr.

>> > Hi;
>> >
[quoted text clipped - 17 lines]
>>
>> Willy.
David Thielen - 01 Jan 2007 20:53 GMT
Hi;

Is there any docs that says what these vars are for the SMTP server? The
problem I have is I can't find any documentation for this so I don't know
what to name the methods.

And even if I got soemthing to work - I have no idea if I am doing this the
correct way or have something that will break on half the systems we install
on.

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

> > Hi;
> >
[quoted text clipped - 34 lines]
> >>
> >> Willy.
David Thielen - 30 Dec 2006 19:45 GMT
Hi;

Or...

Is there a way to run this script -
http://www.systemnetmail.com/forums/forum_viewpost.aspx?forum=2&post=138 from
my C# program?

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

> > Hi;
> >
[quoted text clipped - 14 lines]
>
> Willy.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.