TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Johnny
NA
17
0
Add User to Remote Group
Dec 16 2008 1:25 PM
I am writing a application where I need to add a user to the local admin group on a remote computer. I can get it to work fine on a local computer but It will not work on a remote computer. Here is the code.
DirectoryEntry AD = new DirectoryEntry("WinNT://" + computerAccount, adminAccont, adminPassword);
DirectoryEntry NewUser = new DirectoryEntry();
NewUser = AD.Children.Add(username, "user");
NewUser.Invoke("SetPassword", new object[] { password });
NewUser.Invoke("Put", new object[] { "Description", description });
NewUser.CommitChanges();
AD.RefreshCache();
DirectoryEntry grp = AD.Children.Find("Administrator", "group");
if (grp != null)
{
grp.Invoke("Add", new object[] { NewUser.Path.ToString() });
}
But if I use this to add to a local account it works fine.
DirectoryEntry AD = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
DirectoryEntry NewUser = AD.Children.Add("TestUser1", "user");
NewUser.Invoke("SetPassword", new object[] { "#12345Abc" });
NewUser.Invoke("Put", new object[] { "Description", "Test User from .NET" });
NewUser.CommitChanges();
DirectoryEntry grp;
grp = AD.Children.Find("Guests", "group");
if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }
Any Ideas?
Thanks
Reply
Answers (
8
)
Cannot perform 'LIKE' operation on System.Int32 and System.String
How to use treeview,multiple projects in one solution explorer and search from databases