How to set accountExpires

3
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

c#
asp.net
.net
active-directory
asked on Stack Overflow Sep 13, 2018 by Gullu • edited Sep 26, 2018 by Marilee Turscak - MSFT

1 Answer

2

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.

answered on Stack Overflow Sep 14, 2018 by Marilee Turscak - MSFT • edited Sep 26, 2018 by Marilee Turscak - MSFT

User contributions licensed under CC BY-SA 3.0