473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Set User Account Profile?

Hi
I create a user account in active directory and set the profile value (fill the "homedirectory" and "homedrive" properties and update user account). When I do this steps in "Active Directory Users and Computers", a folder was created and user access the folder. When I do this with program (mentioned above), properties value is set in active directory but the user folder does not create.
Can anyone help me?(My program is written by C#)
Jul 23 '07 #1
3 2262
kenobewan
4,871 Expert 4TB
Welcome to TSDN. Please post your relevant code. Thanks.
Jul 23 '07 #2
Welcome to TSDN. Please post your relevant code. Thanks.
Here is my code:

private void btnCreate_Click(object sender, EventArgs e)
{
int i;
String userName = txtUserName.Text;
String userPassword = txtUserPass.Text;
String domain = txtDomain.Text;
String connectionPrefix = "LDAP://" + domain + "/CN=Users";

i = domain.IndexOf('.');
while (i != -1)
{
connectionPrefix = connectionPrefix + ",DC=" + domain.Substring(0,i);
domain = domain.Remove(0, i + 1);
i = domain.IndexOf('.');
}
connectionPrefix = connectionPrefix + ",DC=" + domain;

DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix, txtAdminUserName.Text, txtAdminPass.Text);
DirectoryEntry newUser = dirEntry.Children.Add("CN=" + userName, "user");
newUser.Properties["samAccountName"].Value = userName;
newUser.Properties["userPrincipalName"].Value = userName + "@" + txtDomain.Text;
newUser.Properties["displayName"].Value = userName;
newUser.Properties["givenName"].Value = userName;
newUser.Properties["msNPAllowDialin"].Value = false;
newUser.Properties["description"].Value = txtDescription.Text;
newUser.CommitChanges();

dirEntry.Close();
newUser.Close();

EnableAndSetProfile();
}


private void EnableAndSetProfile()
{
int i = -1;
try
{
String domain = txtDomain.Text;
String connectionPrefix = "LDAP://" + domain + "/CN=" + txtUserName.Text + ",CN=Users";

i = domain.IndexOf('.');
while (i != -1)
{
connectionPrefix = connectionPrefix + ",DC=" + domain.Substring(0, i);
domain = domain.Remove(0, i + 1);
i = domain.IndexOf('.');
}
connectionPrefix = connectionPrefix + ",DC=" + domain;

DirectoryEntry user = new DirectoryEntry(connectionPrefix, txtAdminUserName.Text, txtAdminPass.Text);

int val = (int)user.Properties["userAccountControl"].Value;
user.Properties["userAccountControl"].Value = 512;
if (txtUserProfile.Text.Trim() != "")
{
if (user.Properties.Contains("HomeDrive"))
user.Properties["HomeDrive"].Value = "Z:";
else
user.Properties["HomeDrive"].Add("Z:");

if (user.Properties.Contains("HomeDirectory"))
user.Properties["HomeDirectory"].Value = txtUserProfile.Text;
else
user.Properties["HomeDirectory"].Add(txtUserProfile.Text);
}

user.CommitChanges();
user.Close();
}
catch(Exception err)
{
MessageBox.Show("Error In Enable User Account.\n" + err.Message);
}
}
Jul 23 '07 #3
Please answer me. Why "Home Directory do not create for new user account with C# Program" ?
Jul 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Wayne Gibson | last post by:
Hi all, Please ignore the other post.. The cat jumped on the machine and sent it before I could stop it!! Was wondering if anybody has expericence this problem.. I am writting an application...
1
by: Bucky Pollard | last post by:
I have a web service that needs to create a batch file and call it (since there are no APIs for the functionality I am looking for). I am using the Process and ProcessStartInfo objects. When I try...
1
by: \Rob\ | last post by:
Why does my ASPNET application create a IWAM_<machinename> user profile? Obviously it runs under the security context of this account but I'm not sure why it creates this profile. I am on a...
4
by: Rik Hemsley | last post by:
Hi, Our web application impersonates a domain user when it runs. Usually, the printers visible to the application are the same as those visible to the domain user. At one installation, the...
4
by: Mike | last post by:
Hi all, In my recent ASP.NET 2.0 appl, I need to verify that the supplied email address is valid or not. So, here's my situation: - In my <profilearea, I created <isVerifiedproperty. - Suppose a...
0
by: underground | last post by:
I have a question more so I need a example of how to achieve this type of php function. I don't have any script I been playing around with the idea in my head and need some expert opinion as well...
3
by: JJ | last post by:
Whats the best way to do this?: Users from different companies need to log into a web site. I want to add the users company name, address etc to their profile. However I want the company details...
3
by: daokfella | last post by:
I want to be able to store profile information for a user when they sign up for an account...but BEFORE they can log in. Can this be done using any of the built-in profile methods? Here's my...
3
by: shapper | last post by:
Hello, On my web site I have a property, Visitor, which is available for Anonymous users: public class Visitor { public CultureInfo Culture { get; set; } public List<GuidPolls { get; set;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.