Tech Off Thread

15 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

The server is unwilling to process the request

Back to Forum: Tech Off
  • User profile image
    W3bbo

    I've written a class to automate user creation (run-of-the-mill really).

    It works flawlessly on my Domain Controller on my LAN, but on two other domain-controllers it fails with this error:

    System.DirectoryServices.DirectoryServicesCOMException

    The server is unwilling to process the request. (Exception from HRESULT: 0x80072035)

       at System.DirectoryServices.DirectoryEntry.CommitChanges()


    And my code:

    private static void CreateUser(Account a, User u) {

    // create a new User object
    DirectoryEntry ou = a.OrganizationalUnit;

    DirectoryEntry newUser = ou.Children.Add("cn=" + u.CN, "user");
    // set addititional properties
    newUser.Properties["sAMAccountName"] .Value = u.SAMAccountName;
    newUser.Properties["userPrincipalName"] .Value = u.PrincipalName;
    newUser.Properties["userAccountControl"].Value = UserAccountControlFlags.NORMAL_ACCOUNT | UserAccountControlFlags.DONT_EXPIRE_PASSWD;

    if( !String.IsNullOrEmpty(u.DisplayName )) newUser.Properties["displayName"].Value = u.DisplayName;
    if( !String.IsNullOrEmpty(u.FirstName )) newUser.Properties["givenName"] .Value = u.FirstName;
    if( !String.IsNullOrEmpty(u.Intiails )) newUser.Properties["initials"] .Value = u.Intiails;
    if( !String.IsNullOrEmpty(u.LastName )) newUser.Properties["sn"] .Value = u.LastName;

    if( u.EmailAddresses.Length >= 1 ) {

    newUser.Properties["mail"].Add( u.EmailAddresses[0] );

    }
    newUser.CommitChanges();
    The exception occurs on the last line there, the .CommitChanges() call.

    The OrganizationalUnit exists and is valid.

    As I said, it works fine on my LAN's DC, but fails on two other (totally separate) domains.

  • User profile image
    Rossj

    W3bbo wrote:
    Exception from HRESULT: 0x80072035)


    Hmm. There is a comment inline on that post that might be useful. Googling HRESULTs nearly always returns what you want Smiley

  • User profile image
    W3bbo

    Rossj wrote:
    
    W3bbo wrote:
    Exception from HRESULT: 0x80072035)


    Hmm. There is a comment inline on that post that might be useful. Googling HRESULTs nearly always returns what you want Smiley


    That's to do with a bug in changing SIDs on XP machines. That's not what I'm doing.

  • User profile image
    W3bbo

    And we have a solution.

    Turns out I'm CommitingChanges before calling SetPassword, since the user has no password it falls foul of Windows' Password policies (which are relaxed on my LAN's DC, but strict on the other two computers).


    Woo.

  • User profile image
    W3bbo

    Dylan Copeland wrote:
    Mr W3bbo, how did you get that formatting to transfer over to the forums. The green comments, blue keywords, etc.

    Thanks.


    My name's David or "Mr. Lord of everything" or casually W3bbo.

    Only one other person has called me "Mister W3bbo", suffice to say he got banned too. I wonder if there's a relation.... Wink

    Anyway, it doesn't transfer over, I color do it manually, but it doesn't take me long to do (2 minutes tops).

    I hate it when people paste code directly into these rich-editors because it screws up linebreaks. Sometimes it wraps each line in its own <pre> element (baaad!), othertimes it puts both real linebreaks and <br /> elements (adding an extra linebreak between lines).

    My technique is to go into HTML view, type in a closed <pre> element with "foo" inside (so it isn't collapsed in Design view), go back to Design view, paste the code directly from VS into it then color it as per usual.

  • User profile image
    W3bbo

    And I discovered something here too...

    To create a user and you've got a password policy in place, then you need to create it with a strong password to begin with.

    But to call SetPassword the user needs to exist in the directory. But it can't exist in the directory because it has no password (because the password policy blocked the .SetInfo / .CommitChanges call).

    The answer is to first create the user with the userAccountControl PASSWD_NOTREQD flag set. This effectivly bypasses the password policies and allows you to create users with no passwords. Once the user is created you can then call .SetPassword.

    To clear the flag, perform a bitwise XOR operation between the existing userAccountControl value and the PASSWD_NOTREQD value.

    Or in my case:

    // perform main property-setting above here
    newUser.Properties["userAccountControl"].Value =
    UserAccountControlFlags.NORMAL_ACCOUNT | UserAccountControlFlags.DONT_EXPIRE_PASSWD | UserAccountControlFlags.PASSWD_NOTREQD;

    newUser.CommitChanges();

    newUser.Invoke("SetPassword", new Object[] { u.Password } );

    UserAccountControlFlags uac = (UserAccountControlFlags)newUser.Properties["userAccountControl"].Value;
    uac = uac ^ UserAccountControlFlags.PASSWD_NOTREQD; // removes passwd_notreq flag
    newUser.Properties["userAccountControl"].Value = uac;

    newUser.CommitChanges();

  • User profile image
    odujosh

    If you copy and paste straight from VS 2005, zing:

    // {[12 CHF][7 USD]} *2 == {[24 CHF][14 USD]}

    Money[] bag = { new Money(24, "CHF"), new Money(14, "USD") };

    MoneyBag expected= new MoneyBag(bag);

    Assert.AreEqual(expected, fMB1.Multiply(2));

    Assert.AreEqual(fMB1, fMB1.Multiply(1));

    Assert.IsTrue(fMB1.Multiply(0).IsZero);


    Very cool eh.

  • User profile image
    odujosh

    odujosh wrote:
    If you copy and paste straight from VS 2005, zing:

    // {[12 CHF][7 USD]} *2 == {[24 CHF][14 USD]}

    Money[] bag = { new Money(24, "CHF"), new Money(14, "USD") };

    MoneyBag expected= new MoneyBag(bag);

    Assert.AreEqual(expected, fMB1.Multiply(2));

    Assert.AreEqual(fMB1, fMB1.Multiply(1));

    Assert.IsTrue(fMB1.Multiply(0).IsZero);


    Very cool eh.



    Edit: Code taking from nUnit samples. Currently looking at Test Driven Development.

  • User profile image
    JohnAskew

    Yes, but the indentations are lost and linefeeds are doubled (yuk):

    public partial class FormMain : Form

    {

    public FormMain()

    {

    InitializeComponent();

    }

    private void btnImport_Click(object sender, EventArgs e)

    {

    ITypeSyncEvent se = Presenter.GetNextSyncEvent("");

    MessageBox.Show(se.EventType.ToString() + Environment.NewLine +

    "Hello World");

    }

    }

  • User profile image
    W3bbo

    JohnAskew wrote:
    Yes, but the indentations are lost and linefeeds are doubled (yuk):

    public partial class FormMain : Form

    {

    public FormMain()

    {

    InitializeComponent();

    }

    private void btnImport_Click(object sender, EventArgs e)

    {

    ITypeSyncEvent se = Presenter.GetNextSyncEvent("");

    MessageBox.Show(se.EventType.ToString() + Environment.NewLine +

    "Hello World");

    }

    }



    ...this, and the last 2 replies are offtopic.

    EDIT: Ah, I see you're testing pasting code.

    Copying and pasting from VS into the editor only works in IE, not Firefox (which is my browser of choice)

  • User profile image
    JohnAskew

    You must mean IE6, because I am using IE7 and VS2005 above... ?
    EDIT: Oh -- I was referring to lack of indentation, not pasting. Sorry.


    ...and you did answer the original poster's question well, W3bbo...

    Smiley

  • User profile image
    W3bbo

    JohnAskew wrote:
    You must mean IE6, because I am using IE7 and VS2005 above... ?
    EDIT: Oh -- I was referring to lack of indentation, not pasting. Sorry.


    ...and you did answer the original poster's question well, W3bbo...

    Smiley


    Have you tried pasting into a <pre> rather than pasting into it normally?

    Because, as you probably know, SGML ignore multiple whitespace characters, except when they're in <pre> or <code> elements (or any box where the appropriate stylesheet whitespace handler is defined, as per the W3C specifications).

  • User profile image
    JohnAskew

    public partial class FormMain : Form

    {

    public FormMain()

    {

    InitializeComponent();

    }

    private void btnImport_Click(object sender, EventArgs e)

    {

    ITypeSyncEvent se = Presenter.GetNextSyncEvent("");

    MessageBox.Show(se.EventType.ToString() + Environment.NewLine +

    "Hello World");

    }

    }





    Well that didn't quite work, still have indentation wrong.

  • User profile image
    odujosh

    Since this post is officially hijaked (good job men)

    How bout in channel9 v4 you guys provide an elegant way of attaching a small file (zip, txt) (lets say 25kb) to a post. Or handle code code snippets elegantly?
     
    Channel 8 is more pretty but lacks functionality. But thats another post.

    (on another note did anyone see flash memory go through the floor, I was at office max the other day 10 bucks for a 512mb stick) So storage shouldn't be much of an issue Smiley There tied it in Tongue Out

    Everyone send in there stick. A SAN of memory sticks. Should be awesome.

  • User profile image
    sebastianso​ny

    I found the solution, I am able to create mailbox .............   Big Smile, the best part is it is working fine from my ASP.NET...

    Many thanks to Timothy H. Schilbach (Timothy.Schilbach_at_NOSPAMcenturytel.com)

    http://www.tech-archive.net/Archive/Exchange/microsoft.public.exchange2000.development/2004-05/0082.html

     

    I got the solution from above link

     

    Many thanks to all.................Smiley:)Smiley:)

     

     

    Make sure you code this in machine where Exchange Server Admin Tools are installed.

    Imports CDOEXM

    Imports System.DirectoryServices

    Imports CDO

    'This function will mailbox enable a user whom already exists

     

    'See if the user exists first

    Dim exUser As DirectoryEntry = New DirectoryEntry("LDAP://AXABS-IN.intraxa/CN=Siena Honda,OU=Test,OU=AXADaemon,OU=Systems and Admins,OU=User Accounts,OU=Business Community,DC=axabs-in,DC=intraxa")

    'Dim exUser As DirectoryEntry = FindUser(UserName)

     

    If Not (Nothing Is exUser) Then

     

    Try

     

    Dim prsmbx As CDO.Person

     

    Dim mbx As IMailboxStore

     

    prsmbx = New CDO.Person

     

    prsmbx.DataSource.Open("LDAP://AXABS-IN.intraxa/CN=Loka Priyan,OU=Test,OU=AXADaemon,OU=Systems and Admins,OU=User Accounts,OU=Business Community,DC=axabs-in,DC=intraxa", , ADODB.ConnectModeEnum.adModeReadWrite)

     

    mbx = prsmbx

     

    ''mbx.CreateMailbox( _

    ''"LDAP://domain.com/CN=Store,CN=StorageGroup," & _

    ''"CN=InformationStore,CN=ServerName,CN=Servers," & _

    ''"CN=First Administrative Group,CN=Administrative Groups," & _

    ''"CN=Domain,CN=Microsoft Exchange,CN=Services," & _

    ''"CN=Configuration,DC=domain,DC=com")

    MessageBox.Show("Creating..")

    mbx.CreateMailbox("CN=Managers,CN=Third Storage Group,CN=InformationStore,CN=PRUIN01EX02,CN=Servers,CN=axaabscoin,CN=Administrative Groups,CN=Axa Business Services,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=adsin,DC=intraxa")

    ' Set some additional mail fields

    MessageBox.Show("Created .")

    With prsmbx

     

    'If Domain.ToLower = "aodinc.com" Then

     

    ' .Email = "SMTP:" & UserName & "@domain.com"

     

    'Else

     

    ' .Email = "SMTP:" & UserName & "@" & Domain

     

    ' .Email2 = "smtp:" & UserName & "@domain.com"

     

    'End If

     

    .Fields.Update()

     

    .DataSource.Save()

     

    End With

    MessageBox.Show("Done")

     

    Catch ex As Exception

    MessageBox.Show(ex.Message)

     

    End Try

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.