MIIS vs WindowsNT – vb.net date conversion useraccountexpires

The cases where you come across Windows NT become rare…
But still…
If you need to connect MIIS to a Windows NT domain, this might help.
A few handy tips.

Although MIIS 2003 and Windows 2003 don’t need WINS anymore, the Windows NT MA (MIIS management agent) does.

So, check the TCP/IP settings of the MIIS server and complete the WINS details.
The date format Windows NT is using (for example for the accountexpires attribute) is calculated differently as on Windows 2000/2003 & Active Directory.
I found an interesting clue on the Citrix support site : http://support.citrix.com/article/CTX109645
The article refers to Windows NT time and Unix time as follows:
"Windows NT time is specified as the number of 100 nanosecond intervals since January 1, 1601. UNIX time is specified as the number of seconds since January 1, 1970."
Actually an odd choice of words… because if you connect MIIS to WindowsNT and verify the accountexpires attribute (for example) it is using seconds from 1/1/1970 as reference. Just like Citrix’ Unix time.
So in fact, Windows NT is using Unix time.
Let’s rephrase it to Windows time and Unix (compliant) time,  meaning "Windows time" using 100 nanoseconds units from 1/1/1601 0:00 and "Unix time" using seconds units from 1/1/1970 00:00.
The Citrix support document also offers a basic calculation to convert one to another.
Below you’ll find a few simple code snippets for VB.NET.
I suppose the date/datetime libraries loaded (if not load them as reference and import them in the project code)
    Public Function unixTimetoWinTime( _
    ByVal unixTime As Long) As Long
        Return (unixTime + 11644473600) * 10000000
    End Function
    Public Function WinTimetoUnixTime( _
    ByVal winTime As Long) As Long
        Return (winTime / 10000000) – 11644473600
    End Function
    Public Function UnixTimeToStringWintime( _
    ByVal lgUnixTime As Long) As String
        Dim lgDate As Long = unixTimetoWinTime(lgUnixTime)
        Return Date.FromFileTime(lgDate).ToString
    End Function
    Public Function DateStringToLongUnixtime( _
        ByVal strDate As String) As Long
        Dim lgDate As Long = DateValue(strDate).ToFileTime
        Return WinTimetoUnixTime(lgdate)
    End Function
BTW, have you noticed: if you try to set 1/1/1970 as expiry date for an user account in WinNT using user manager for domains, WinNT automatically sets 1/1/1980.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s