【问题标题】:how to set "password never expires" through C# code [duplicate]如何通过C#代码设置“密码永不过期”[重复]
【发布时间】:2019-12-06 06:21:56
【问题描述】:

使用下面的代码,我可以创建一个有密码的用户,但是如何启用“密码永不过期”标志?

using (var process = new Process())
{
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.RedirectStandardOutput = false;
    process.StartInfo.UseShellExecute = true;

    process.StartInfo.Arguments = $"user test-user Password1 /add";
    process.StartInfo.FileName = "net";
    process.Start();
    process.WaitForExit();
}

【问题讨论】:

标签: c# system.diagnostics


【解决方案1】:

net user documentation 表示有一个expires 选项可以与never 一起使用,如下所示:

process.StartInfo.Arguments = $"user test-user Password1 /add /expires:never";

但您可能不应该在 C# 代码中使用 net user,当有替代品时调用 shell 进程是不好的做法。

【讨论】:

  • 你能举个例子吗
  • 我认为您的问题在 cmets 中有一些很好的链接
  • 这不是我的问题,但谢谢
  • 这不起作用
  • 这只是设置帐户到期而不是密码到期。
猜你喜欢
  • 2012-06-17
  • 1970-01-01
  • 2020-07-15
  • 2010-12-18
  • 1970-01-01
  • 2011-06-05
  • 1970-01-01
  • 2019-03-27
  • 2010-11-23
相关资源
最近更新 更多