0

With below code, I am able to create a user with password, but how to enable "password never expires" flag?

enter image description here

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();
}
Siavash Rostami
  • 1,883
  • 4
  • 17
  • 31
user584018
  • 10,186
  • 15
  • 74
  • 160
  • Chek https://stackoverflow.com/questions/11025495/set-windows-ad-password-so-that-it-never-expires. You should not be using "net" calls. – Alek Davis Dec 06 '19 at 06:26
  • 4
    Does this answer your question? [Set Windows/AD password so that it "never expires"?](https://stackoverflow.com/questions/11025495/set-windows-ad-password-so-that-it-never-expires) – Jonas W Dec 06 '19 at 06:27

1 Answers1

0

The net user documentation says there is an expires option that ca used with never, like this:

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

But you should probably not use net user in your C# code, it's bad practice calling shell processes when there are alternatives.

ShamPooSham
  • 2,301
  • 2
  • 19
  • 28