Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
区分windows server 2016和2019_Windows_Vb6 - Fatal编程技术网

区分windows server 2016和2019

区分windows server 2016和2019,windows,vb6,Windows,Vb6,我想做的事情的总结。使用rtlGetVersion确定windows server 2016和2019之间的差异,使用版本号(如1803/1809)而不是最新版本的内部版本号 我正在修复使用GetVersionEx转换为rltGetVersion的旧代码。大部分代码都是编写的,所以这只是实现它的问题。使用此链接 问题是windows server 2016和19具有相同的字段,因此无法使用此设置确定是哪个字段。使用。我知道windows 2016版本为1803,2019版本为1809 我遇到的

我想做的事情的总结。使用
rtlGetVersion
确定windows server 2016和2019之间的差异,使用版本号(如1803/1809)而不是最新版本的内部版本号


我正在修复使用GetVersionEx转换为rltGetVersion的旧代码。大部分代码都是编写的,所以这只是实现它的问题。使用此链接

问题是windows server 2016和19具有相同的字段,因此无法使用此设置确定是哪个字段。使用。我知道windows 2016版本为1803,2019版本为1809

我遇到的问题是,使用rtlGetVersion会创建这样一个结构

而建造编号是我能得到的最接近的。但情况发生了变化。我想知道是否有人知道一种获取构建版本而不是构建编号的方法,如果这有意义的话

这是第一个链接中使用的代码

'==================================================================================
' RealWinVer.bas     by Cody Gray, 2016
' 
' (Freely available for use and modification, provided that credit is given to the
' original author. Including a comment in the code with my name and/or a link to
' this Stack Overflow answer is sufficient.)
'==================================================================================

Option Explicit

''''''''''''''''''''''''''''''''''''''''''''''''''
' Windows SDK Constants, Types, & Functions
''''''''''''''''''''''''''''''''''''''''''''''''''

Private Const cbCSDVersion As Long = 128 * 2

Private Const STATUS_SUCCESS As Long = 0

Private Const VER_PLATFORM_WIN32s As Long        = 0
Private Const VER_PLATFORM_WIN32_WINDOWS As Long = 1
Private Const VER_PLATFORM_WIN32_NT As Long      = 2

Private Const VER_NT_WORKSTATION As Byte       = 1
Private Const VER_NT_DOMAIN_CONTROLLER As Byte = 2
Private Const VER_NT_SERVER As Byte            = 3

Private Const VER_SUITE_PERSONAL As Integer = &H200

Private Type RTL_OSVERSIONINFOEXW
   dwOSVersionInfoSize As Long
   dwMajorVersion      As Long
   dwMinorVersion      As Long
   dwBuildNumber       As Long
   dwPlatformId        As Long
   szCSDVersion        As String * cbCSDVersion
   wServicePackMajor   As Integer
   wServicePackMinor   As Integer
   wSuiteMask          As Integer
   wProductType        As Byte
   wReserved           As Byte
End Type

Private Declare Function RtlGetVersion Lib "ntdll" _
    (lpVersionInformation As RTL_OSVERSIONINFOEXW) As Long


''''''''''''''''''''''''''''''''''''''''''''''''''
' Internal Helper Functions
''''''''''''''''''''''''''''''''''''''''''''''''''

Private Function IsWinServerVersion(ByRef ver As RTL_OSVERSIONINFOEXW) As Boolean
   ' There are three documented values for "wProductType".
   ' Two of the values mean that the OS is a server versions,
   ' while the other value signifies a home/workstation version.
   Debug.Assert ver.wProductType = VER_NT_WORKSTATION Or _
                ver.wProductType = VER_NT_DOMAIN_CONTROLLER Or _
                ver.wProductType = VER_NT_SERVER

   IsWinServerVersion = (ver.wProductType <> VER_NT_WORKSTATION)
End Function

Private Function GetWinVerNumber(ByRef ver As RTL_OSVERSIONINFOEXW) As String
   Debug.Assert ver.dwPlatformId = VER_PLATFORM_WIN32_NT

   GetWinVerNumber = ver.dwMajorVersion & "." & _
                     ver.dwMinorVersion & "." & _
                     ver.dwBuildNumber
End Function

Private Function GetWinSPVerNumber(ByRef ver As RTL_OSVERSIONINFOEXW) As String
   Debug.Assert ver.dwPlatformId = VER_PLATFORM_WIN32_NT

   If (ver.wServicePackMajor > 0) Then
      If (ver.wServicePackMinor > 0) Then
         GetWinSPVerNumber = "SP" & CStr(ver.wServicePackMajor) & "." & CStr(ver.wServicePackMinor)
         Exit Function
      Else
         GetWinSPVerNumber = "SP" & CStr(ver.wServicePackMajor)
         Exit Function
      End If
   End If
End Function

Private Function GetWinVerName(ByRef ver As RTL_OSVERSIONINFOEXW) As String
   Debug.Assert ver.dwPlatformId = VER_PLATFORM_WIN32_NT

   Select Case ver.dwMajorVersion
      Case 3
         If IsWinServerVersion(ver) Then
            GetWinVerName = "Windows NT 3.5 Server"
            Exit Function
         Else
            GetWinVerName = "Windows NT 3.5 Workstation"
            Exit Function
         End If
      Case 4
         If IsWinServerVersion(ver) Then
            GetWinVerName = "Windows NT 4.0 Server"
            Exit Function
         Else
            GetWinVerName = "Windows NT 4.0 Workstation"
            Exit Function
         End If
      Case 5
         Select Case ver.dwMinorVersion
            Case 0
               If IsWinServerVersion(ver) Then
                  GetWinVerName = "Windows 2000 Server"
                  Exit Function
               Else
                  GetWinVerName = "Windows 2000 Workstation"
                  Exit Function
               End If
            Case 1
               If (ver.wSuiteMask And VER_SUITE_PERSONAL) Then
                  GetWinVerName = "Windows XP Home Edition"
                  Exit Function
               Else
                  GetWinVerName = "Windows XP Professional"
                  Exit Function
               End If
            Case 2
               If IsWinServerVersion(ver) Then
                  GetWinVerName = "Windows Server 2003"
                  Exit Function
               Else
                  GetWinVerName = "Windows XP 64-bit Edition"
                  Exit Function
               End If
            Case Else
               Debug.Assert False
         End Select
      Case 6
         Select Case ver.dwMinorVersion
            Case 0
               If IsWinServerVersion(ver) Then
                  GetWinVerName = "Windows Server 2008"
                  Exit Function
               Else
                  GetWinVerName = "Windows Vista"
                  Exit Function
               End If
            Case 1
               If IsWinServerVersion(ver) Then
                  GetWinVerName = "Windows Server 2008 R2"
                  Exit Function
               Else
                  GetWinVerName = "Windows 7"
                  Exit Function
               End If
            Case 2
               If IsWinServerVersion(ver) Then
                  GetWinVerName = "Windows Server 2012"
                  Exit Function
               Else
                  GetWinVerName = "Windows 8"
                  Exit Function
               End If
            Case 3
               If IsWinServerVersion(ver) Then
                  GetWinVerName = "Windows Server 2012 R2"
                  Exit Function
               Else
                  GetWinVerName = "Windows 8.1"
                  Exit Function
               End If
            Case Else
               Debug.Assert False
         End Select
      Case 10
         If IsWinServerVersion(ver) Then
            GetWinVerName = "Windows Server 2016"
            Exit Function
         Else
            GetWinVerName = "Windows 10"
            Exit Function
         End If
      Case Else
         Debug.Assert False
   End Select

   GetWinVerName = "Unrecognized Version"
End Function


''''''''''''''''''''''''''''''''''''''''''''''''''
' Public Functions
''''''''''''''''''''''''''''''''''''''''''''''''''

' Returns a string that contains the name of the underlying version of Windows,
' the major version of the most recently installed service pack, and the actual
' version number (in "Major.Minor.Build" format).
'
' For example: "Windows Server 2003 SP2 (v5.2.3790)" or
'              "Windows 10 (v10.0.14342)"
'
' This function returns the *real* Windows version, and works correctly on all
' operating systems, including Windows 10, regardless of whether or not the
' application includes a manifest. It calls the native NT version-info function
' directly in order to bypass compatibility shims that would otherwise lie to
' you about the real version number.
Public Function GetActualWindowsVersion() As String
   Dim ver As RTL_OSVERSIONINFOEXW
   ver.dwOSVersionInfoSize = Len(ver)

   If (RtlGetVersion(ver) <> STATUS_SUCCESS) Then
      GetActualWindowsVersion = "Failed to retrieve Windows version"
   End If

   ' The following version-parsing logic assumes that the operating system
   ' is some version of Windows NT. This assumption will be true if you
   ' are running any version of Windows released in the past 15 years,
   ' including several that were released before that.
   Debug.Assert ver.dwPlatformId = VER_PLATFORM_WIN32_NT

   GetActualWindowsVersion = GetWinVerName(ver) & " " & GetWinSPVerNumber(ver) & _
                             " (v" & GetWinVerNumber(ver) & ")"
End Function
'==================================================================================
“RealWinVer.bas由科迪·格雷创作,2016年
' 
(免费提供使用和修改,前提是
'原始作者。在代码中包含带有我的姓名的注释和/或链接到
'此堆栈溢出回答已足够。)
'==================================================================================
选项显式
''''''''''''''''''''''''''''''''''''''''''''''''''
'Windows SDK常量、类型和函数
''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const CBCSD版本,长度=128*2
Private Const STATUS_SUCCESS,只要=0
Private Const VER_PLATFORM_WIN32s的长度=0
Private Const VER_PLATFORM_WIN32_WINDOWS(长=1)
Private Const VER_PLATFORM_WIN32_NT的长度=2
专用常量版本工作站,字节=1
私有常量版本域控制器,字节=2
专用常量版本服务器,字节=3
Private Const VER_SUITE_PERSONAL As Integer=&H200
私有类型RTL_OSVersionInfo EXW
dwOSVersionInfoSize尽可能长
dwMajorVersion尽可能长
只要
dwBuildNumber尽可能长
长的扁平状的
szCSDVersion为字符串*cbCSDVersion
wServicePackMajor作为整数
wServicePackMinor作为整数
wSuiteMask作为整数
wProductType作为字节
字节
端型
专用声明函数RtlGetVersion Lib“ntdll”_
(lpVersionInformation作为RTL_OSVersionInfo)只要
''''''''''''''''''''''''''''''''''''''''''''''''''
'内部助手函数
''''''''''''''''''''''''''''''''''''''''''''''''''
私有函数IsWinServerVersion(ByRef ver作为RTL_OSVERSIONINFOEXW)作为布尔值
“wProductType”有三个记录在案的值。
'其中两个值表示操作系统是服务器版本,
'而另一个值表示主/工作站版本。
Debug.Assert ver.wProductType=ver\u NT\u工作站或_
ver.wProductType=ver\u NT\u DOMAIN\u控制器或_
ver.wProductType=ver\u NT\u服务器
IsWinServerVersion=(ver.wProductType ver\u NT\u工作站)
端函数
私有函数GetWinVerNumber(ByRef ver作为RTL_OSVersionInfo)作为字符串
Debug.Assert ver.dwPlatformId=ver\u PLATFORM\u WIN32\n
GetWinVerNumber=ver.dwMajorVersion&“&”_
版本dwMinorVersion&“&”_
版本号
端函数
私有函数GetWinSPVerNumber(ByRef ver作为RTL_OSVersionInfo)作为字符串
Debug.Assert ver.dwPlatformId=ver\u PLATFORM\u WIN32\n
如果(ver.wServicePackMajor>0),则
如果(ver.wServicePackMinor>0),则
GetWinSPVerNumber=“SP”&CStr(版本wServicePackMajor)&CStr(版本wServicePackMinor)
退出功能
其他的
GetWinSPVerNumber=“SP”&CStr(版本wServicePackMajor)
退出功能
如果结束
如果结束
端函数
私有函数GetWinVerName(ByRef ver作为RTL_OSVersionInfo)作为字符串
Debug.Assert ver.dwPlatformId=ver\u PLATFORM\u WIN32\n
选择Case ver.dwMajorVersion
案例3
如果是WinServerVersion(版本),则
GetWinVerName=“Windows NT 3.5服务器”
退出功能
其他的
GetWinVerName=“Windows NT 3.5工作站”
退出功能
如果结束
案例4
如果是WinServerVersion(版本),则
GetWinVerName=“Windows NT 4.0服务器”
退出功能
其他的
GetWinVerName=“Windows NT 4.0工作站”
退出功能
如果结束
案例5
选择Case ver.dwMinorVersion
案例0
如果是WinServerVersion(版本),则
GetWinVerName=“Windows 2000服务器”
退出功能
其他的
GetWinVerName=“Windows 2000工作站”
退出功能
如果结束
案例1
如果(版本wSuiteMask和版本SUITE\u PERSONAL),则
GetWinVerName=“Windows XP Home Edition”
退出功能
其他的
GetWinVerName=“Windows XP Professional”
退出功能
如果结束
案例2
如果是WinServerVersion(版本),则
GetWinVerName=“Windows Server 2003”
退出功能
其他的
GetWinVerName=“Windows XP 64位版本”
退出功能
如果结束
其他情况
Debug.Assert为False
结束选择
案例6
选择Case ver.dwMinorVersion
案例0
如果是WinServerVersion(版本),则
GetWinVerName=“Windows Server 2008”
退出功能
其他的
GetWinVerName=“Windows Vista”
退出功能
如果结束
案例1
如果是WinServer