Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating local users on remote windows server using c#

Tags:

c#

.net

windows

Provided I have admin access, I need a way to manage (Create, modify, remove) local accounts in a remote machine from an ASP.NET client.

I'm clueless in how to approach this. Is WMI a possibility (System.Management namespace)? Any pointers?

like image 310
user25885 Avatar asked Oct 15 '22 18:10

user25885


1 Answers

Give this a try:

DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://ComputerName" & ",computer", "AdminUN", "AdminPW");
DirectoryEntry user = directoryEntry.Children.Add("username", "user");
user.Invoke("SetPassword", new object[] { "password"});
ser.CommitChanges();

If you do need to go the Active Directory route, you can change the directoryEntry path string to something like this: LDAP://CN=ComputerName,DC=MySample,DC=com

like image 58
Matt Hanson Avatar answered Oct 18 '22 09:10

Matt Hanson