Creating NT User accounts using ADSI (WinNT:) within VB.Net 
Author Message
 Creating NT User accounts using ADSI (WinNT:) within VB.Net

Hello,

Can anybody please tell me how to create a NT useraccount using ADSI (WinNT
provider) and which properties are available ?

I can find lots of resources using VB6 or VBScript but none that are usable
with VB.Net

Thanks in advance,

Peter Tijsma



Sun, 09 Jan 2005 21:19:21 GMT  
 Creating NT User accounts using ADSI (WinNT:) within VB.Net
Set a reference to System.DirectoryServices, create a new DirectoryEntry
with your ADSI path, and it works in an almost identical way. The main
difference is that you have to go through the property collection, and any
methods have to be accessed through "Invoke".

E.g.:

VBScript:

Sub AddUser(strUser, strDomain, strFullName, strPassword, strDescription)
    Dim Computer : Set Computer = GetObject("WinNT://" & strDomain)
    Dim User : Set User = Computer.Create("User", strUser)
    User.FullName = strFullName
    User.Description = strDescription
    Call User.SetInfo()
    Call User.SetPassword(strPassword)
End Sub

VB.Net:

Imports System.DirectoryServices

Sub AddUser(ByVal strUser As String, ByVal strDomain As String, strFullName,
strPassword, strDescription)
    Dim Computer As New DirectoryEntry("WinNT://" & strDomain)
    Dim User As DirectoryEntry = Computer.Children.Add(strUser, "User")
    User.Properties("FullName").Value = strFullName
    User.Properties("Description").Value = strDescription
    User.CommitChanges()
    User.Invoke("SetPassword", strPassword)
End Sub


Quote:
> Hello,

> Can anybody please tell me how to create a NT useraccount using ADSI
(WinNT
> provider) and which properties are available ?

> I can find lots of resources using VB6 or VBScript but none that are
usable
> with VB.Net

> Thanks in advance,

> Peter Tijsma



Mon, 10 Jan 2005 00:00:45 GMT  
 Creating NT User accounts using ADSI (WinNT:) within VB.Net
Hi Richard,

I was trying what you had suggested for Peter, but I am finding that the
User.Properties are read only when I try to set them and then do the
commit...  is there something I'm missing?

Thanks!

Matt

P.S.  Is there a way to easily list all of the available properties in the
object (User) ?


Quote:
> Set a reference to System.DirectoryServices, create a new DirectoryEntry
> with your ADSI path, and it works in an almost identical way. The main
> difference is that you have to go through the property collection, and any
> methods have to be accessed through "Invoke".

> E.g.:

> VBScript:

> Sub AddUser(strUser, strDomain, strFullName, strPassword, strDescription)
>     Dim Computer : Set Computer = GetObject("WinNT://" & strDomain)
>     Dim User : Set User = Computer.Create("User", strUser)
>     User.FullName = strFullName
>     User.Description = strDescription
>     Call User.SetInfo()
>     Call User.SetPassword(strPassword)
> End Sub

> VB.Net:

> Imports System.DirectoryServices

> Sub AddUser(ByVal strUser As String, ByVal strDomain As String,
strFullName,
> strPassword, strDescription)
>     Dim Computer As New DirectoryEntry("WinNT://" & strDomain)
>     Dim User As DirectoryEntry = Computer.Children.Add(strUser, "User")
>     User.Properties("FullName").Value = strFullName
>     User.Properties("Description").Value = strDescription
>     User.CommitChanges()
>     User.Invoke("SetPassword", strPassword)
> End Sub



> > Hello,

> > Can anybody please tell me how to create a NT useraccount using ADSI
> (WinNT
> > provider) and which properties are available ?

> > I can find lots of resources using VB6 or VBScript but none that are
> usable
> > with VB.Net

> > Thanks in advance,

> > Peter Tijsma



Sun, 06 Feb 2005 21:38:20 GMT  
 Creating NT User accounts using ADSI (WinNT:) within VB.Net

Quote:
>     User.Properties("FullName").Value = strFullName
>     User.Properties("Description").Value = strDescription

Should read:

    User.Properties("FullName").Add( strFullName)
    User.Properties("Description").Add( strDescription)
...

Use Value if you want to get/set an "existing" property value.

Willy.

Quote:

> Hi Richard,

> I was trying what you had suggested for Peter, but I am finding that the
> User.Properties are read only when I try to set them and then do the
> commit...  is there something I'm missing?

> Thanks!

> Matt

> P.S.  Is there a way to easily list all of the available properties in the
> object (User) ?



> > Set a reference to System.DirectoryServices, create a new DirectoryEntry
> > with your ADSI path, and it works in an almost identical way. The main
> > difference is that you have to go through the property collection, and any
> > methods have to be accessed through "Invoke".

> > E.g.:

> > VBScript:

> > Sub AddUser(strUser, strDomain, strFullName, strPassword, strDescription)
> >     Dim Computer : Set Computer = GetObject("WinNT://" & strDomain)
> >     Dim User : Set User = Computer.Create("User", strUser)
> >     User.FullName = strFullName
> >     User.Description = strDescription
> >     Call User.SetInfo()
> >     Call User.SetPassword(strPassword)
> > End Sub

> > VB.Net:

> > Imports System.DirectoryServices

> > Sub AddUser(ByVal strUser As String, ByVal strDomain As String,
> strFullName,
> > strPassword, strDescription)
> >     Dim Computer As New DirectoryEntry("WinNT://" & strDomain)
> >     Dim User As DirectoryEntry = Computer.Children.Add(strUser, "User")
> >     User.Properties("FullName").Value = strFullName
> >     User.Properties("Description").Value = strDescription
> >     User.CommitChanges()
> >     User.Invoke("SetPassword", strPassword)
> > End Sub



> > > Hello,

> > > Can anybody please tell me how to create a NT useraccount using ADSI
> > (WinNT
> > > provider) and which properties are available ?

> > > I can find lots of resources using VB6 or VBScript but none that are
> > usable
> > > with VB.Net

> > > Thanks in advance,

> > > Peter Tijsma



Sun, 06 Feb 2005 21:48:27 GMT  
 Creating NT User accounts using ADSI (WinNT:) within VB.Net
Excellent! Thank you very much!



Quote:
> >     User.Properties("FullName").Value = strFullName
> >     User.Properties("Description").Value = strDescription

> Should read:

>     User.Properties("FullName").Add( strFullName)
>     User.Properties("Description").Add( strDescription)
> ...

> Use Value if you want to get/set an "existing" property value.

> Willy.




Quote:
> > Hi Richard,

> > I was trying what you had suggested for Peter, but I am finding that the
> > User.Properties are read only when I try to set them and then do the
> > commit...  is there something I'm missing?

> > Thanks!

> > Matt

> > P.S.  Is there a way to easily list all of the available properties in
the
> > object (User) ?



> > > Set a reference to System.DirectoryServices, create a new
DirectoryEntry
> > > with your ADSI path, and it works in an almost identical way. The main
> > > difference is that you have to go through the property collection, and
any
> > > methods have to be accessed through "Invoke".

> > > E.g.:

> > > VBScript:

> > > Sub AddUser(strUser, strDomain, strFullName, strPassword,
strDescription)
> > >     Dim Computer : Set Computer = GetObject("WinNT://" & strDomain)
> > >     Dim User : Set User = Computer.Create("User", strUser)
> > >     User.FullName = strFullName
> > >     User.Description = strDescription
> > >     Call User.SetInfo()
> > >     Call User.SetPassword(strPassword)
> > > End Sub

> > > VB.Net:

> > > Imports System.DirectoryServices

> > > Sub AddUser(ByVal strUser As String, ByVal strDomain As String,
> > strFullName,
> > > strPassword, strDescription)
> > >     Dim Computer As New DirectoryEntry("WinNT://" & strDomain)
> > >     Dim User As DirectoryEntry = Computer.Children.Add(strUser,
"User")
> > >     User.Properties("FullName").Value = strFullName
> > >     User.Properties("Description").Value = strDescription
> > >     User.CommitChanges()
> > >     User.Invoke("SetPassword", strPassword)
> > > End Sub



> > > > Hello,

> > > > Can anybody please tell me how to create a NT useraccount using ADSI
> > > (WinNT
> > > > provider) and which properties are available ?

> > > > I can find lots of resources using VB6 or VBScript but none that are
> > > usable
> > > > with VB.Net

> > > > Thanks in advance,

> > > > Peter Tijsma



Sun, 06 Feb 2005 22:56:51 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Creating an NT user account in VB

2. VB WIN 32 API TO CREATE A USER ACCOUNT ON NT/2000

3. How to Create an NT User Account with VB 5.0

4. WinNT Accounts within VB

5. Renaming user accounts using ADSI, example not working

6. Modify NT User Accounts from within Visual Basic

7. Modify NT User Accounts from within Visual Basic

8. Using ADSI to change NT user properties

9. create user account in an NT-DOMAIN

10. Creating NT User Accounts

11. Creating user accounts on NT

12. Creating User/Computer account in NT Domain

 

 
Powered by phpBB® Forum Software