How to use GetObject in CShaprt

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

We can use GetObject to load the instance of COM form file like:

Dim CADObject As Object
CADObject = GetObject("C:\CAD\SCHEMA.CAD")

How can we implement the two statements above in CSharp?
 
Hi ad,

object CADObject;
CADObject = GetObject("C:\CAD\SCHEMA.CAD");

I'm not sure what the C# version of GetObject is, but you can use the
Visual Basic one.
You will need to add the Microsoft.VisualBasic namespace as well as a
reference to the VisualBasic assembly (Microsoft.VisualBasic.dll I
suspect).
 
Use :
object CADObject = Marshal.BindToMoniker("C:\\CAD\\SCHEMA.CAD");

but, why not write this in vb.net which much better suited for COM interop
using late bound objects.

Willy.
 
I have using Microsoft.VisualBasic namespace as well as a reference to
the microsoft.visualbasic.dll, but it still faill in compile time with the
error message:
GetObject doesn't exist in the namespace of class..
My code is below:

object domain;
domain = GetObject("WinNT://Workgroup/MyComputerName");
 
ad said:
I have using Microsoft.VisualBasic namespace as well as a reference to
the microsoft.visualbasic.dll, but it still faill in compile time with the
error message:
GetObject doesn't exist in the namespace of class..
My code is below:

object domain;
domain = GetObject("WinNT://Workgroup/MyComputerName");


You are trying to bind to the ADSI provider using a moniker as you used to
do in VB, this is not required in .NET.
The System.DirectoryServices namespace classes like DirectoryEntry and
DirectorySearcher are wrappers arround ADSI and should be used instead.

Willy.
 
I have read the help in VS.net, but the document is few.
Are there any documents about DirectoryEntry and
DirectorySearcher ?
I want to use ADSI to manage the users in my domain.
 
ad said:
I have read the help in VS.net, but the document is few.
Are there any documents about DirectoryEntry and
DirectorySearcher ?
I want to use ADSI to manage the users in my domain.

What domain are you running? If it's an NT4 domain, it's not worth the
trouble to learn all this.
If it's a W2K or higher domain, just check this:
http://msdn.microsoft.com/library/d.../active_directory_service_interfaces_adsi.asp

and the samples:

http://msdn.microsoft.com/library/d.../active_directory_service_interfaces_adsi.asp

But before you dive into this stuff make sure you have a basic understanding
of directory services and ADSI.

Willy.
 
Thank,
But the two links you mentioned are the same.

I have used the codes below to insert all groups in my server into a
DroupDownList,
But how can I list the users in a specified group?



----------------------------------------------------------------------------
-------------------------------------------
DirectoryEntry1.Path="WinNT://WorkGroup/ServerName/";
if (!this.IsPostBack)
{
foreach(System.DirectoryServices.DirectoryEntry child in
DirectoryEntry1.Children)
{

switch (child.SchemaClassName)
{
case "Group" :
DropDownList1.Items.Add(child.Name);
break;
}
}//foreach
}




I have use the ADSI
 
Great.
In that case you should use "LDAP://.." in you AD path, there are only a few
cases where you need WinNT as protocol provider.

Willy.
 
Thank!
I found that if I want manage the accountS or vitual directoryS of IIS,
I must use WinNT as protocol provider.
Are there any articles about ADSI for IIS?
 
Yes there is, take a look at "Using ADSI to Configure IIS"
(http://msdn.microsoft.com/library/d...us/iissdk/iis/using_adsi_to_configure_iis.asp).
Another (prefered on w2k3) option is to use WMI (wrapped by
System.Management classes in .NET)
But you can't use the WinNT provider to manage virtual directories in IIS,
IIS uses "IIS://..." as provider path.
Don't know for sure what you mean with "accounts of IIS". So I assume that
we are talking about Windows accounts, that can be used to authenticate them
from IIS/asp.net, these accounts are stored in:
1. Domain accounts: the AD on a W2K/W2K3 domain and managed using the ADSI
interface using the LDAP provider.
2. Local accounts: the local SAM's DB on the server and here you should use
WinNT as provider.

Willy.
 
Thank,
I have study the link aobut IIS, but all the example is written by VB, I
have try to rewrite it to c#, but it is some difficult.
Are there any exmple about IIS which are written by c#?
 
I have copy my adsi project from my notebook to the Windows 2003 Server.
But it fail in run time with message
System.Runtime.InteropServices.COMException: write/read deny?

How can I do?
 
Please learn to post the exception message or the complete call stack.
Also post a short but complete working sample that illustrates the problem
you have.
Without these we are unable to help you out.

Willy.
 
Back
Top