3

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.

4

5 回答 5

2

这不是特定于 python 的,但您可以通过systeminfoandfind命令找到它。

>systeminfo | find /i "original"
Original Install Date:     7/27/2011, 3:06:49 PM

如果安装区域设置为英语,则该字符串original适用。

您可以将其包装在os.system电话中

>>> os.system("""systeminfo | find /i "original" """)
Original Install Date:     7/27/2011, 3:06:49 PM
于 2014-06-10T15:01:54.973 回答
0
def getInstallDate():
  cache = os.popen2("SYSTEMINFO")
  info = cache[1].read()
  label = "Original Install Date:" 
  return info.split(label)[-1].split("\n")[0].strip()
于 2014-06-10T15:38:54.853 回答
0

你可以试试

import os

info = os.popen('cmd /k systeminfo | find "Original Install Date"').read();
print info
#Original Install Date:     5/12/2014, 9:06:04 AM

我还没有研究subprocess包,但它是推荐的选项。os 将完成工作。

于 2014-06-10T14:59:50.937 回答
0

使用 Windows 注册表:

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)
于 2014-06-10T15:10:27.283 回答
-1

尝试:

import platform
print platform.system(), platform.release()
于 2014-06-10T14:56:55.890 回答