The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,869 other followers

Archive for October 11th, 2009

C# / .NET – setting or clearing the Password Never Expires flag for a user

Posted by jpluimers on 2009/10/11

Recently, I had to change the “Password Never Expires” flag for some users on Windows systems.

In the past, there used to be a netuser tool available from WindowsITPro where you could use the pwnexp flag to set or clear that flag.
That tool seems to be vanished, so I was searching for alternatives.

Most alternatives I found depend on some  kind of scripting, or the use of the WMIC WMI command line interface: that was “out” because this particular setup is running on Windows XP Embedded, which is trimmed down very much.
The only C# example I found was on CodeProject, but it does

  • not take into account the existing flags correctly,
  • have  hard coded literals without any references where they are from,
  • use bit flag arithmetic without letting the C# compiler do its magic with enums,
  • use a call to the deprecated  InvokeGet method,
  • use the Invoke(“Put”, … way of calling that so many people use (which actually should have been an – also deprecated – InvokeSet method),
  • use COM Interop

Hence the solution below:
C#, with the proper ADS_USER_FLAG_ENUM enum from the MSDN documentation and no COM Interop, it also moves all literals to constants.

Read the rest of this entry »

Posted in .NET, C#, C# 2.0, CommandLine, Development, Software Development, XP-embedded | Leave a Comment »

%d bloggers like this: