Windows - 本地用户管理

发布于 2024-10-17 21:41:01 字数 760 浏览 11 评论 0原文

我正在尝试实现一个脚本/实用程序,用于重命名用户、设置默认密码,然后提示用户在 Windows Server 2003 中首次登录时更改密码。我能够完成前 2 项,但不能完成后两项第三。具体来说,我希望用户遇到 Windows 对话框,其中显示以下内容:“您需要在首次登录时更改密码”然后将他们带到“更改密码”对话框,其中有“确定”和“取消”按钮。如果他们点击取消,他们将被带到初始登录屏幕。

我实现了下面的代码来尝试完成此任务。我得到的行为是,向用户提供一个对话框,指出密码已过期且必须更改,并提示用户这样做。但是,用户只需单击“取消”,用户就会登录。该实用程序是用 C# 编写的脚本,但如果它能让事情变得更容易,我愿意使用其他语言。

DirectoryEntry directory = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntry userEntry = directory.Children.Find("defaultUsername"); 
userEntry.Rename("theUser");
userEntry.Invoke("SetPassword", new object[] { "defaultPassword" });
userEntry.Properties["PasswordExpired"].Value = 1; 
userEntry.Properties["UserFlags"].Value = 0x800201; 
userEntry.CommitChanges();

I am trying to implement a script/utility that renames a user, sets a default password, and then will prompt the user to change their password on their initial logon in Windows Server 2003. I am able to accomplish the first 2 items but not the third. Specifically, I want the user to encounter the Windows dialog box that states the following :"you are required to change your password at first logon" Then it takes them to the "Change Password" dialog box which has an OK and Cancel button. If they hit cancel, they are taken to the initial login screen.

I implemented the code below to try to accomplish this. The behavior I am getting instead is that the user is given a dialog box that states that the password has expired and must changed, is prompted to do so. However, the user can simply click Cancel, and the user is logged in. The utility is scripted in c# but I am open to another language if it makes things easier.

DirectoryEntry directory = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntry userEntry = directory.Children.Find("defaultUsername"); 
userEntry.Rename("theUser");
userEntry.Invoke("SetPassword", new object[] { "defaultPassword" });
userEntry.Properties["PasswordExpired"].Value = 1; 
userEntry.Properties["UserFlags"].Value = 0x800201; 
userEntry.CommitChanges();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妖妓 2024-10-24 21:41:01

您无法使用 UserFlags 0x800000 将密码设置为过期 - 请参阅

You can't use UserFlags 0x800000 to set a password as expired - see here. Using PasswordExpired = 1 should be sufficient. Did you try this with UserFlags = 0x201?

凤舞天涯 2024-10-24 21:41:01

userEntry.Properties["密码已过期"].Value = 0;

我认为这就是问题所在

userEntry.Properties["PasswordExpired"].Value = 0;

I think thats the issue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文