用VB得到windows系统安装时的时间(for NT,2000,XP,..)

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6


Option Explicit

Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_DWORD = 4

Function GetWindowsNTInstallTime() As String
    On Error Resume Next
    Dim InstallDateValue As Long
    Dim hKey As Long
    Dim ret As String
    If RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE/Microsoft/Windows NT/CurrentVersion", hKey) = 0 Then
       If RegQueryValueEx(hKey, "InstallDate", 0&, REG_DWORD, InstallDateValue, 4) = 0 Then
          ret = CStr(InstallDateValue)
       End If
       If hKey Then RegCloseKey hKey
    End If
    If ret <> "" Then
        GetWindowsNTInstallTime = DateAdd("s", CLng(ret), "1970-01-01 00:00")
    Else
        GetWindowsNTInstallTime = "时间未知"
    End If
End Function

Private Sub Command1_Click()
    MsgBox "当前系统的安装时间为:" & GetWindowsNTInstallTime, vbInformation, ""
End Sub

'-------------------------------------------
' 作者:唐细刚

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: windows