How to set accountExpires

Viewed 441
dirEntry.Properties["userAccountControl"].Value = val & ~0x2; //enable user
//above line no error but below line get error
dirEntry.Properties["accountExpires"].Value = DateTime.UtcNow.AddDays(1).ToFileTimeUtc();

The error thrown is errMsg = "System.Runtime.InteropServices.COMException (0x80004005): Unspecified error\r\n\r\n at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.PutEx(Int32 lnControlCode, String bstrName, Object vProp)\r\n at System.DirectoryServices.PropertyValueColl...

Please advise. If it was a permission issue I would have gotten an error on the first line ... On premise AD (not Azure) Thanks

1 Answers

For those who come here with the same issue, this fixed it . . .

Convert.ToString((Int64)DateTime.UtcNow.AddDays(1).ToFileTimeUtc())

See this thread for a more detailed discussion.

Related