Creation of NT User Account & Exchange Mailbox

Creation of NT User Account & Exchange Mailbox

Post by Hong Ten » Fri, 12 May 2000 04:00:00



Hi there,

I would want to write a VB6.0 background process which creates
i.  NT User account in Win2k Server and
ii. respective Exchange 5.5 mailbox for a list of users.

For this purpose, I have tried out the Acctcrt.dll control that enable me to
create part ( i ). From the sample codes attached in MSDN library for
Acctcrt.dll component, I have fall into several problems.

First part of codes that I have simplified for extracting SID for user
account created,

    Dim acctcrt As MSExchangeAcctLib.AcctMgmt
    Dim varSID As Variant

    Set acctcrt = New MSExchangeAcctLib.AcctMgmt
    'Extract SID for administrator
    Call acctcrt.GetSidFromName("DomainName", "administrator", varSID)

    MsgBox "Administrator SID = " & CStr(varSID)

I'm hoping that the .GetSidFromName function from Acctcrt.dll to return the
SID for account that I have created.  However, the message displayed is
"Administrator SID =  ???????????????" .  It returns a Nothing or empty
string.  Can anyone of you tell me what's the reason for this ? is varSID
being declared wrongly ?

Anyone of you have tried out the codes attached together with this .dll file
? I'm having difficulty in some of the declaration part, which I hope I have
figured it out properly. Please pin point any mistakes I have done.

    Dim Acct As MSExchangeAcctLib.AcctMgmt
    Dim strDomain As String
    Dim strUser As String
    Dim strPassword As String
    Dim strReturn As String
    Dim varSecurityDescriptor As Variant
    Dim varSecurityID As Variant
    Dim strDelivContTypes As String
    Dim recipcont_obj As IADs
    Dim recip_obj As IADs

    Set Acct = New MSExchangeAcctLib.AcctMgmt

    strUser = txtUserName.Text
    strPassword = txtPassword.Text

    'Create NT User Account into Viztel Domain
    strDomain = "Viztel"
    Call Acct.NtAccountCreate(strDomain, _
                              strUser, _
                              strPassword, _
                              "", "")

    'Get the SID and descriptor for the directory object
    Call Acct.GetSidFromName(strDomain, strUser, varSecurityID)
    Call Acct.GenerateSecDescriptor(strDomain, strUser,
varSecurityDescriptor)

    'convert the default value below so its suitable for ADSI/LDAP Transport

    strDelivContTypes = "2A864886F7140501"

    'Create the mailbox in the DS with ADSI
    strPath = "LDAP://Servername/o=org/ou=site/cn=Microsoft
DMD/cn=Address-Home"

    Set recipcont_obj = GetObject(CStr(strPath))
    Set recip_obj = recipcont_obj.Create("OrganizationPerson", "cn=MBName")

    'set the required attributes for the directory object
    recip_obj.Put "Deliv-Ext-Cont-Types", strDelivContTypes
    recip_obj.Put "NT-Security-Descriptor", CStr(varSecurityDescriptor)
    recip_obj.Put "Assoc-NT-Account", varSecurityID
    recip_obj.Put "FullName", txtFullName.Text

    recip_obj.SetInfo

    MsgBox "Account " & strUser & " Created Successfully"

For this chunk of codes, I have the following message at recip_obj.SetInfo,
which I suspect it's due to the empty string return in the
varSecurityDescriptor, am I right ?

Run Time Error '-2147016694 (8007200a)'
Automation Error

I appreciate if you could provide any advices, suggestions and helps to me

Thank you in advance.

Regards,
Hong Teng

 
 
 

Creation of NT User Account & Exchange Mailbox

Post by Greg J Frate » Fri, 12 May 2000 04:00:00


If you would rather use an existing tool that will do this for you look into
www.tools4nt.com.  They have a free tool called UserManagement lite.  It is very
flexible and will read a list of user names from a text file and create both the
NT account and the Exchange mail box.


> Hi there,

> I would want to write a VB6.0 background process which creates
> i.  NT User account in Win2k Server and
> ii. respective Exchange 5.5 mailbox for a list of users.

> For this purpose, I have tried out the Acctcrt.dll control that enable me to
> create part ( i ). From the sample codes attached in MSDN library for
> Acctcrt.dll component, I have fall into several problems.

> First part of codes that I have simplified for extracting SID for user
> account created,

>     Dim acctcrt As MSExchangeAcctLib.AcctMgmt
>     Dim varSID As Variant

>     Set acctcrt = New MSExchangeAcctLib.AcctMgmt
>     'Extract SID for administrator
>     Call acctcrt.GetSidFromName("DomainName", "administrator", varSID)

>     MsgBox "Administrator SID = " & CStr(varSID)

> I'm hoping that the .GetSidFromName function from Acctcrt.dll to return the
> SID for account that I have created.  However, the message displayed is
> "Administrator SID =  ???????????????" .  It returns a Nothing or empty
> string.  Can anyone of you tell me what's the reason for this ? is varSID
> being declared wrongly ?

> Anyone of you have tried out the codes attached together with this .dll file
> ? I'm having difficulty in some of the declaration part, which I hope I have
> figured it out properly. Please pin point any mistakes I have done.

>     Dim Acct As MSExchangeAcctLib.AcctMgmt
>     Dim strDomain As String
>     Dim strUser As String
>     Dim strPassword As String
>     Dim strReturn As String
>     Dim varSecurityDescriptor As Variant
>     Dim varSecurityID As Variant
>     Dim strDelivContTypes As String
>     Dim recipcont_obj As IADs
>     Dim recip_obj As IADs

>     Set Acct = New MSExchangeAcctLib.AcctMgmt

>     strUser = txtUserName.Text
>     strPassword = txtPassword.Text

>     'Create NT User Account into Viztel Domain
>     strDomain = "Viztel"
>     Call Acct.NtAccountCreate(strDomain, _
>                               strUser, _
>                               strPassword, _
>                               "", "")

>     'Get the SID and descriptor for the directory object
>     Call Acct.GetSidFromName(strDomain, strUser, varSecurityID)
>     Call Acct.GenerateSecDescriptor(strDomain, strUser,
> varSecurityDescriptor)

>     'convert the default value below so its suitable for ADSI/LDAP Transport

>     strDelivContTypes = "2A864886F7140501"

>     'Create the mailbox in the DS with ADSI
>     strPath = "LDAP://Servername/o=org/ou=site/cn=Microsoft
> DMD/cn=Address-Home"

>     Set recipcont_obj = GetObject(CStr(strPath))
>     Set recip_obj = recipcont_obj.Create("OrganizationPerson", "cn=MBName")

>     'set the required attributes for the directory object
>     recip_obj.Put "Deliv-Ext-Cont-Types", strDelivContTypes
>     recip_obj.Put "NT-Security-Descriptor", CStr(varSecurityDescriptor)
>     recip_obj.Put "Assoc-NT-Account", varSecurityID
>     recip_obj.Put "FullName", txtFullName.Text

>     recip_obj.SetInfo

>     MsgBox "Account " & strUser & " Created Successfully"

> For this chunk of codes, I have the following message at recip_obj.SetInfo,
> which I suspect it's due to the empty string return in the
> varSecurityDescriptor, am I right ?

> Run Time Error '-2147016694 (8007200a)'
> Automation Error

> I appreciate if you could provide any advices, suggestions and helps to me

> Thank you in advance.

> Regards,
> Hong Teng

--
Greg Frater
Net Admin
(509) 371-3537