简体   繁体   中英

How to set accountExpires

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM