pythonwindows-xp-sp3

Check the installation date of Windows XP


Is it possible to check, using Python programming languque, the time on which the operating system is installed ? Mainly, I am interested in Windows XP platform. I wonder if there is such an API in python or any trick to do it.


Solution

  • Using the Windows registry:

    import _winreg as reg
    from datetime import datetime
    
    key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')
    secs = reg.QueryValueEx(key, 'InstallDate')[0] # This is stored as a UNIX timestamp
    date = datetime.fromtimestamp(secs)