Sub get_cp() '獲得作業系統
Dim wbemServices, yan
Dim objSWbemObjectSet
Dim objSWbemObject
Set wbemServices = GetObject(“winmgmts:\.\root\cimv2”)
Set yan = CreateObject(“WScript.Shell”) '用于讀取系統資料庫的對象
OP_TYPE = “”
Set objSWbemObjectSet = wbemServices.InstancesOf(“Win32_OperatingSystem”)
For Each objSWbemObject In objSWbemObjectSet
CPP1 = “”: cpp2 = “”: cpp3 = “”
CPP1 = Trim(objSWbemObject.Caption) & " " & Trim(objSWbemObject.CSDVersion) & vbCrLf '作業系統:
Cpp_Xp = False
Cpp_Xp = (InStr(1, CPP1, “XP”) = 0 And InStr(1, CPP1, “2003”) = 0) '是否非XP和2003 作業系統,true 代表不是XP
If Cpp_Xp Then
cpp2 = Trim(objSWbemObject.OSArchitecture) & vbCrLf '"資料位寬:",OSArchitecture=64-bit'XP 和 2003 不支援
Else
cpp2 = "32-bit" & vbCrLf
End If
cpp3 = Trim(objSWbemObject.Version) & vbCrLf ' "系統版本:"
CPP1 = Replace(CPP1, "?", "")
CPP1 = Replace(CPP1, " ", " ")
CPP1 = UCase(CPP1)
If InStr(1, CPP1, "WINDOWS XP") > 0 Then SYSTEM_TYPE = "XP"
If InStr(1, CPP1, "WINDOWS VISTA") > 0 Then SYSTEM_TYPE = "VISTA"
If InStr(1, CPP1, "WINDOWS 7") > 0 Then SYSTEM_TYPE = "WIN7"
If InStr(1, CPP1, "WINDOWS 8") > 0 Then SYSTEM_TYPE = "WIN8"
If InStr(1, CPP1, "WINDOWS 10") > 0 Then SYSTEM_TYPE = "WIN10"
If InStr(1, CPP1, "SERVER 2003") > 0 Then SYSTEM_TYPE = "2003"
If InStr(1, CPP1, "SERVER 2008") > 0 Then SYSTEM_TYPE = "2008"
If InStr(1, CPP1, "SERVER 2008 R2") > 0 Then SYSTEM_TYPE = "2008R2"
If InStr(1, CPP1, "SERVER 2010") > 0 Then SYSTEM_TYPE = "2010"
If InStr(1, CPP1, "SERVER 2010 R2") > 0 Then SYSTEM_TYPE = "2010R2"
If InStr(1, CPP1, "SERVER 2012") > 0 Then SYSTEM_TYPE = "2012"
If InStr(1, CPP1, "SERVER 2012 R2") > 0 Then SYSTEM_TYPE = "2012R2"
If InStr(1, CPP1, "SERVER 2016") > 0 Then SYSTEM_TYPE = "2016"
If InStr(1, CPP1, "SERVER 2016 R2") > 0 Then SYSTEM_TYPE = "2016R2"
Exit For
Next
'***************************作業系統名稱、版本*****************************************************************88
Get_If = Get_If & "作業系統:" & CPP1 '作業系統名稱及sp版本
IS_64X = Val(cpp2) > 0 '是否是64位作業系統
OP_TYPE = SYSTEM_TYPE & "-" & Val(cpp2) '作業系統類型
Set objSWbemObject = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemServices = Nothing
Set yan = Nothing
End Sub