如何判断本机安装的是服务器端的操作系统(如Win2000Server)还是客户端的操作系统呢(如Win2000Professional)。100分酬谢!在线等待
解决方案 »
- 大家帮忙看看这是什么表格控件?
- 如何获得第i个记录的第i个字段的数据?
- 请教高手:如何在MSFlexGrid控件中显示复选框
- 各位大侠,我问一下你们认为共享软件能不能转钱,到底一个月能转多少!什么样的软件好买
- 高手快来帮忙啊 一个控件问题
- 高分求购EMAIL控件!!帮忙!
- excel自动换行后,打印预览时显示不全
- 想删除表里某字段有重复值的SQL语句怎么写?
- treeview 问题
- how to make the width of a statusbar = form width and automatic resize?
- VB中如何得到局端的DNS解析服务器的地址!
- 奇怪,怎么在SQL生成器里不能使用变量?
http://vbnet.mvps.org/code/helpers/iswinversion.htm
Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByVal lpVersionInformation As OSVERSIONINFO) As Long
说明
在一个OSVERSIONINFO结构中载入与平台和操作系统有关的版本信息
返回值
Long,非零表示成功,零表示失败
参数表
参数 类型及说明
lpVersionInformation OSVERSIONINFO,用于装载版本信息的结构。在正式调用函数之前,必须先将这个结构的dwOSVersionInfoSize字段设为结构的大小(148) OSVERSIONINFO 类型定义
Type OSVERSIONINFO ' 148 Bytes
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
说明
This structure contains operating system version information. This structure is used with the GetVersionEx function.
字段表
字段 类型与说明
dwOSVersionInfoSize Long,Size of this data structure, currently at 148 bytes. This field must be set before calling the GetVersionEx function.
dwMajorVersion Long,Specifies the major and minor version number of the operating system.
dwMinorVersion
dwBuildNumber Long,Specifies the build number of the operating system. On Windows 95, build 1000 respresents OEM service release #2.
dwPlatformId Long,Specifies the platform supported by the operating system. May be one of the following:VER_PLATFORM_WIN32s: Win32s on Windows 3.1.VER_PLATFORM_WIN32_WINDOWS: Win32 on Windows 95.VER_PLATFORM_WIN32_NT: Windows NT.
szCSDVersion String,Contains additional information about the operating system
^@^
Private Type OSVERSIONINFOEX
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
wSPMajor As Integer
wSPMinor As Integer
wSuiteMask As Integer
bProductType As Byte
bReserved As Byte
End Type
这个结构中的bProductType 就是你想要的数据,它有三中可能,msdn解释:
VER_NT_WORKSTATION
The system is running Windows NT 4.0 Workstation, Windows 2000 Professional, Windows XP Home Edition, or Windows XP Professional.
值为1
VER_NT_DOMAIN_CONTROLLER
The system is a domain controller.
值为2
VER_NT_SERVER
The system is a server.
值为3
知道这些你就可写代码实现了
声明必要的api
Private Type OSVERSIONINFOEX
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
wSPMajor As Integer
wSPMinor As Integer
wSuiteMask As Integer
bProductType As Byte
bReserved As Byte
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long
Private Sub Form_Load()
Dim lpVersionInfo As OSVERSIONINFOEX lpVersionInfo.dwOSVersionInfoSize = Len(lpVersionInfo)
‘长度要提供给api,否则api不知道长度,没法传递会数据 ret& = GetVersionEx(lpVersionInfo)
Select Case lpVersionInfo.bProductType
Case 1
Label1.Caption = "NT_WORKSTATION"
Case 2
Label1.Caption = "NT_DOMAIN_CONTROLLER"
Case 3
Label1.Caption = "NT_SERVER"
Case Else
Label1.Caption = ""
End Select
End Sub
http://vbnet.mvps.org/index.html?code/wmi/wmoperatingsystem.htm
以下是取当前系统的代码
Option ExplicitPrivate Sub Command1_Click()
Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject
Dim msg As String
Dim dtb As String
Dim d As String
Dim t As String
Dim bias As Long
On Local Error Resume Next
Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_OperatingSystem")
For Each obj In wmiObjSet
MsgBox "你当前使用的系统是" & obj.Caption
Next
End Sub