I'm trying to write an application that will create and admin account and downgrade the current account from admin to guest. Is this possible and how would I go about achieving this?
DirectoryEntry AD = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
var currentUserName = Environment.UserName;
var currentUser = AD.Children.Find(currentUserName, "user");
var adminGroup = AD.Children.Find("Administrators", "group");
var guestGroup = AD.Children.Find("Guests", "group");
guestGroup.Invoke("Add", new object[] { currentUser.Path });
adminGroup.Invoke("Remove", new object[] { currentUser.Path });
This is what I currently have. It doesn't throw any exceptions but when I check my account it remains an admin account. What am I doing wrong?
Also, since I am doing this inside of a WindowsSandbox, where it ultimately is supposed to be deployed, there is no way for me to reboot without losing the account. Is there a way to refresh without rebooting the whole system(if that is the actual problem)?