[IronPython] Adding user to local group

Iain iain at onesquared.net
Thu Jun 14 03:35:11 PDT 2007


I am wanting to add a local user to a local group and I have been unable 
to find any examples of this.  There is no shortage of examples for 
Active Directory but nothing relating to local groups.

 From what I can work out the code should be something like
group = System.DirectoryServices.DirectoryEntry("WinNT://" + 
System.Environment.MachineName + "/testgroup")
group.Properties["member"].Add("testuser")

This fails with "EnvironmentError: The directory property cannot be 
found in the cache." the first time then "EnvironmentError: Exception 
from HRESULT: 0x8000500F"

For AD groups the code is,
group = System.DirectoryServices.DirectoryEntry("WinNT://" + 
System.Environment.MachineName + "/testgroup")
user = System.DirectoryServices.DirectoryEntry("WinNT://" + 
System.Environment.MachineName + "/testuser")
group.Properties["member"].Add(user.Properties["distinguishedName"].Value)

But with local users there is no distinguishedName property.

Any ideas?

Iain.


More information about the users mailing list