Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Create a User

CRM 1.0

In order to create a user, the user name must have already been added to Windows Active Directory. This can either be done by hand or programmatically.

For more information about Active Directory, see the documentation on MSDN (www.microsoft.com/windows2000/technologies/directory/ad/default.asp).

For more information about the Active Directory SDK, see the documentation on MSDN (msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/ad/active_directory.asp).

Class Reference

Schema Reference

  • systemuser.xsd



// The precondition for this code to work is that there needs to be
// an organization, a business unit within the organization, and a user
// within the business unit whose domainname corresponds to the 
// Active Directory name of the currently logged on user

public void CreateUser()
   // strServer should be set with the name of the platform Web server
   String strServer = "MyServerName";

   // strVirtualDirectory should be set with the name of the Microsoft CRM
   // virtual directory on the platform Web server
   String strVirtualDirectory = "mscrmservices";
   String strDir = String.Concat("http://", strServer, "/",
                                  strVirtualDirectory, "/");

   // BizUser proxy object
   Microsoft.Crm.Platform.Proxy.BizUser bizUser 
               = new Microsoft.Crm.Platform.Proxy.BizUser ();
   bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
   bizUser.Url = String.Concat(strDir, "BizUser.srf");

   String strErrorMsg;
   String strUserName;
      Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI();

      // The 'domainname' field must map to an existing Active Directory
      // user's name. At the same time, if that name is already used to
      // create a user, it cannot be reused

      strUserName = "Reed_Koch";

      // For this sample code to succeed, 'Reed_Koch' must be a valid user
      // in the domain where the code is run, and none of the existing
      // Microsoft CRM users already map to it
      StringBuilder userXml 
           = new StringBuilder("<systemuser><firstname>Reed</firstname>");
      userXml.AppendFormat("<domainname>{0}</domainname>", userName);
      // Create the user
      String strUserId = bizUser.Create(userAuth, userXml.ToString());
   catch (System.Web.Services.Protocols.SoapException err)
      // Process the platform error here
      strErrorMsg = String.Concat("ErrorMessage: ", err.Message, " ",
                      err.Detail.OuterXml, " Source: ", err.Source);

© 2005 Microsoft Corporation. All rights reserved.

© 2015 Microsoft