1
我有一段代碼可以創建Windows用戶。一切都很好,用戶確實創建。但是,當我試圖鎖定LoadUserProfile時,操作失敗,因爲用戶不在Users組中。現在,我知道如何以實用的方式將用戶添加到Users組,但我不想硬編碼組名「Users」,因爲它可能會根據語言環境而更改。有沒有辦法將用戶添加到默認的用戶組(順便說一下,runas user/add命令已經這樣做了)?默認情況下,如何向用戶組添加新的Windows用戶
DirectoryEntry dirEntry = new DirectoryEntry("WinNT://" + domain);
DirectoryEntries entries = dirEntry.Children;
DirectoryEntry user = entries.Add(username, "User");
user.Properties["FullName"].Add("Dr Zoidberg");
user.Invoke("SetPassword", password);
user.CommitChanges();
謝謝,就是這樣! – kateroh 2010-09-21 03:26:35