Solved

How to know which OS we r using?

Posted on 2001-08-24
9
250 Views
Last Modified: 2008-03-06
Is there any API function to know, which operating system is being used whether its Windows98/ME/2000?
0
Comment
Question by:rinosh
9 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6421451
Hi,

Obtaining Windows' Version Information:http://www.mvps.org/vbnet/code/system/getversionex.htm
0
 
LVL 39

Expert Comment

by:appari
ID: 6421458
use GetVersionEx API to get the OS details
0
 
LVL 1

Expert Comment

by:sanjeevjain1973
ID: 6421462
Add microsoft sysinfo control in your project

add a command button in your form & gice name of your sysinfo control name sysDetectOS
then run following code


Private Sub Command1_Click()

   Dim MsgEnd As String
   Select Case sysDetectOS.OSPlatform
      Case 0
         MsgEnd = "Unidentified"
      Case 1
         MsgEnd = "Windows 95, ver. " & _
CStr(sysDetectOS.OSVersion) & "(" & _
CStr(sysDetectOS.OSBuild) & ")"
      Case 2
         MsgEnd = "Windows NT, ver. " & _
CStr(sysDetectOS.OSVersion) & "(" & _
CStr(sysDetectOS.OSBuild) & ")"
   End Select
   MsgBox "System: " & MsgEnd

End Sub

sanjeev
0
 

Expert Comment

by:kuppachi
ID: 6421483
GetVersionEx gives u the info about the OS.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:sanjeevjain1973
ID: 6421544
Using microsoft sysinfo control . you can read many other property related operating system.

Sanjeev
0
 

Expert Comment

by:CTrip
ID: 6421580
A Complete answer:
Create a form and past the following lines into it:

Private Sub Command1_Click()
Dim sHold3 As String, sPath As String
sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion"
sHold3 = GetFieldFromRec(1, "Version", ",")
MsgBox (RegGetStringValue(HKEY_LOCAL_MACHINE, sPath, sHold3))
End Sub


'------------------
Create a Module and past the following lines into it:


Option Explicit

' -----------------
' ADVAPI32
' -----------------
' function prototypes, constants, and type definitions
' for Windows 32-bit Registry API

Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_READ = &H20000
Public Const STANDARD_RIGHTS_WRITE = &H20000
Public Const STANDARD_RIGHTS_EXECUTE = &H20000
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Const REG_DWORD = 4
Public Const REG_BINARY = 3
Public Const REG_SZ = 1
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const ERROR_SUCCESS = 0&

' Registry API prototypes

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
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
Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long

Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long

Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public syspath As String

Function WindowsDirectory() As String 'get windows directory
Dim WinPath As String
Dim temp
    WinPath = String(145, Chr(0))
    temp = GetWindowsDirectory(WinPath, 145)
    WindowsDirectory = Left(WinPath, InStr(WinPath, Chr(0)) - 1)
syspath = WindowsDirectory
End Function


Public Function RegGetStringValue(hKey As Long, sPath As String, sValue As String)
    Dim lKeyHand As Long
    Dim lValueType As Long
    Dim lResult As Long
    Dim sBuff As String
    Dim lDataBufSize As Long
    Dim iZeroPos As Integer
   
    RegOpenKey hKey, sPath, lKeyHand                            'open the key we are looking at
    lResult = RegQueryValueEx(lKeyHand, sValue, 0&, lValueType, ByVal 0&, lDataBufSize)
    If lValueType = REG_SZ Then                                 'is it a Null terminated string?
        sBuff = String$(lDataBufSize, " ")                      'set the Buffer size
        lResult = RegQueryValueEx(lKeyHand, sValue, 0&, 0&, ByVal sBuff, lDataBufSize)
        If lResult = ERROR_SUCCESS Then
            iZeroPos = InStr(sBuff, Chr$(0))                    'is there a null in the returned value?
            If Not iZeroPos = 0 Then
                RegGetStringValue = Left$(sBuff, iZeroPos - 1)       'yes? then get everything up to the null, and return the value
            Else
                RegGetStringValue = sBuff                           'no?  then return the value
            End If
        End If
    End If
    RegCloseKey lKeyHand
End Function

Function RegGetEnumValue(hKey As Long, sPath As String)
    Dim lKeyHandle As Long, lResult As Long, lCurIdx As Long
    Dim sValue As String, sResult As String
    Dim lValueLen As Long, lData As Long, lDataLen As Long
   
    lResult = RegOpenKeyEx(hKey, sPath, 0&, KEY_READ, lKeyHandle)       'Open the path we are going to enumerate
    If Not lResult = ERROR_SUCCESS Then Exit Function                   'if we fail, then exit >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    Do
        lValueLen = 2000
        sValue = String(lValueLen, 0)
        lDataLen = 2000
        lResult = RegEnumValue(lKeyHandle, lCurIdx, ByVal sValue, lValueLen, 0&, REG_DWORD, ByVal lData, lDataLen)
        lCurIdx = lCurIdx + 1
        If lResult = ERROR_SUCCESS Then                                 'does the item exist
            sResult = Left(sValue, lValueLen) & "," & sResult
        End If
    Loop While lResult = ERROR_SUCCESS                                  'loop until we run out of items
    Call RegCloseKey(lKeyHandle)
    If Not Len(sResult) = 0 Then sResult = Left(sResult, Len(sResult) - 1)  'remove the last comma
    RegGetEnumValue = sResult
End Function

Function CountItems(sField As String, sSep As String) As Integer
'Counts the number of items in a delimited string
'Pass the String that has the list, and the seperator
'iCount = sField, sSep
'sField = the list, sSep is the seperator to count by
    Dim bNotFound As Boolean
    Dim iPos As Integer, iCount As Integer
   
    Do Until bNotFound                                 'loop until we have counted all the items
        iPos = InStr(iPos + 1, sField, sSep)
        If iPos = 0 Then
            bNotFound = True                            'if we are done, then leave
        Else
            iCount = iCount + 1                         'increment the counter
        End If
    Loop
    CountItems = iCount                                 'return what we found
End Function

Public Function GetFieldFromRec(iFieldNum As Integer, sLine As String, sSep As String) As String
    'Returns a field from a record separated by a passed character
    'Calling syntax:
    'sR = GetFieldFromRec(i, s, c)
    'where i is the field number (0 based), s is the record string, c is the separating character
    Dim i        As Integer
    Dim iTabPos  As Integer
    Dim sTemp    As String
   
    For i = 1 To iFieldNum
        iTabPos = InStr(iTabPos + 1, sLine, sSep)
    Next i
    sTemp = Mid$(sLine, iTabPos + 1) & sSep         'Truncate unwanted preceding fields
    sTemp = Mid$(sTemp, 1, InStr(sTemp, sSep) - 1)  'Truncate unwanted following fields
    GetFieldFromRec = sTemp
End Function
Public Function ShowatStartup()
'Put calender in the registry
Dim Reg As New clsEasyRegistry
Dim avntVariable As Variant
Dim lngType As Long
Dim lngJ As Long
  Reg.Cd "\HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN"
  Reg.ValueOf("EnCryptor", erSTRING) = App.Path & "\EnCryptor.exe"
  avntVariable = Reg.ValueOf("EnCryptor", lngType)
  Select Case lngType
    Case erSTRING
      Debug.Print "Type : " & "String"
  End Select
  Debug.Print "Value (Hex) : " & avntVariable(erStringFormat)
  Debug.Print
 
End Function
Public Function DontShowatStartup()
'Put calender in the registry
Dim Reg As New clsEasyRegistry
Dim avntVariable As Variant
Dim lngType As Long
Dim lngJ As Long
'If CalendarColor.chkShowatStartup.Value = 0 Then
  Reg.Cd "\HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN"
  Reg.ValueOf("EnCryptor", erSTRING) = App.Path & "\EnCryptor.exe"
  Reg.DeleteValue "EnCryptor"
'  End If
End Function

Public Function LoadSet()
' Retrieve the settings.
Dim MySettings As Variant, intSettings As Integer
MySettings = GetAllSettings(Appname:="Calender Options", Section:="Startup")
   For intSettings = LBound(MySettings, 1) To UBound(MySettings, 1)
      Debug.Print MySettings(intSettings, 0), MySettings(intSettings, 1)
   Next intSettings
End Function
Public Function DeleteSet()
DeleteSetting "Calender Options", "Startup"
DontShowatStartup
End Function


0
 

Expert Comment

by:CTrip
ID: 6421609
For More Details About The System, Add The following To the
"Private Sub Command1_Click()":

Dim sHold As String, sHold1 As String
Dim sHold2 As String, sHold3 As String
Dim sHold4 As String

sHold = GetFieldFromRec(1, "RegisteredOwner", ",")
sHold1 = GetFieldFromRec(1, "RegisteredOrganization", ",")
sHold2 = GetFieldFromRec(1, "SystemRoot", ",")
sHold3 = GetFieldFromRec(1, "Version", ",")
sHold4 = GetFieldFromRec(1, "VersionNumber", ",")

MsgBox (RegGetStringValue(HKEY_LOCAL_MACHINE, sPath, sHold))
MsgBox (RegGetStringValue(HKEY_LOCAL_MACHINE, sPath, sHol1))
MsgBox (RegGetStringValue(HKEY_LOCAL_MACHINE, sPath, sHold2))
MsgBox (RegGetStringValue(HKEY_LOCAL_MACHINE, sPath, sHold3))
MsgBox (RegGetStringValue(HKEY_LOCAL_MACHINE, sPath, sHold4))

Hope it's will help :)

0
 
LVL 1

Accepted Solution

by:
Ryan9999 earned 50 total points
ID: 6421654
here ya goOption Explicit

Const VER_PLATFORM_WIN32s = 0
Const VER_PLATFORM_WIN32_WINDOWS = 1
Const VER_PLATFORM_WIN32_NT = 2

Private Type OSVersionInfo
  OSVSize As Long
  dwVerMajor As Long
  dwVerMinor As Long
  dwBuildNumber As Long
  PlatformID As Long
  szCSDVersion As String * 128
End Type

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
  (lpVersionInformation As OSVersionInfo) As Long
 
Private Function GetOSVer() As String
  Dim osv As OSVersionInfo
  osv.OSVSize = Len(osv)
  If GetVersionEx(osv) = 1 Then
    Select Case osv.PlatformID
      Case Is = VER_PLATFORM_WIN32s
        GetOSVer = "Windows 3.x"
      Case Is = VER_PLATFORM_WIN32_WINDOWS
        Select Case osv.dwVerMinor
          Case Is = 0
            If InStr(UCase(osv.szCSDVersion), "C") Then
              GetOSVer = "Windows 95 OSR2"
            Else
              GetOSVer = "Windows 95"
            End If
          Case Is = 10
            If InStr(UCase(osv.szCSDVersion), "A") Then
              GetOSVer = "Windows 98 SE"
            Else
              GetOSVer = "Windows 98"
            End If
          Case Is = 90
            GetOSVer = "Windows Me"
        End Select
      Case Is = VER_PLATFORM_WIN32_NT
        Select Case osv.dwVerMajor
          Case Is = 3
            Select Case osv.dwVerMinor
              Case Is = 0
                GetOSVer = "Windows NT 3"
              Case Is = 1
                GetOSVer = "Windows NT 3.1"
              Case Is = 5
                GetOSVer = "Windows NT 3.5"
              Case Is = 51
                GetOSVer = "Windows NT 3.51"
            End Select
          Case Is = 4
            GetOSVer = "Windows NT 4"
          Case Is = 5
            Select Case osv.dwVerMinor
              Case Is = 0
                GetOSVer = "Windows 2000"
              Case Is = 1
                GetOSVer = "Whistler"
            End Select
        End Select
    End Select
  End If
End Function

0
 

Author Comment

by:rinosh
ID: 6424362
Thanks for the solution!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now