Click to See Complete Forum and Search --> : Help!! Need to determine OS
lphu
Jan 10th, 2001, 03:11 PM
Is these an API call to return the type of OS is running,
i.e. Windows NT or Windows 98? I would greatly appreciate any help. Thanks in advance...
Vlatko
Jan 10th, 2001, 03:34 PM
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Sub Form_Load()
Dim OSInfo As OSVERSIONINFO, PId As String
'Set the graphical mode to persistent
Me.AutoRedraw = True
'Set the structure size
OSInfo.dwOSVersionInfoSize = Len(OSInfo)
'Get the Windows version
Ret& = GetVersionEx(OSInfo)
'Chack for errors
If Ret& = 0 Then MsgBox "Error Getting Version Information": Exit Sub
'Print the information to the form
Select Case OSInfo.dwPlatformId
Case 0
PId = "Windows 32s "
Case 1
PId = "Windows 95/98"
Case 2
PId = "Windows NT "
End Select
Print "OS: " + PId
Print "Win version:" + str$(OSInfo.dwMajorVersion) + "." + LTrim(str(OSInfo.dwMinorVersion))
Print "Build: " + str(OSInfo.dwBuildNumber)
End Sub
If PId = 0 then it should be Windows 3.x
Help
Jan 10th, 2001, 04:59 PM
You can also get this information w. RegOpenKeyEx .
Path is
HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENT VERSION\
keys = Product Version
Product Name
Version number
etc.
:)
overhill
Jan 11th, 2001, 02:25 PM
Using the code that Vlatko provided, what does Windows ME return? Is it the same as Windows 95/98?
By using the method Help gave you, you can be even more specific with regard to what your product is. For example, if pID = 1 then you are not sure whether it's Win95, 98 or ME, whereas the registry method will specify what version it is.
Here is some code that corrosponds to Help's method.
Add to a Module
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 RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal HKEY As Long, ByVal lpValueName As String) 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 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 RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
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 REG_SZ = 1
Function RegQueryStringValue(ByVal HKEY As Long, ByVal strValueName As String)
Dim lResult As Long
Dim lValueType As Long
Dim strBuf As String
Dim lDataBufSize As Long
On Error GoTo 0
lResult = RegQueryValueEx(HKEY, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(HKEY, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
RegQueryStringValue = StripTerminator(strBuf)
End If
End If
End If
End Function
Public Function GetSettingEx(HKEY As Long, sPath As String, sValue As String)
Dim KeyHand&
Dim datatype&
Call RegOpenKey(HKEY, sPath, KeyHand&)
GetSettingEx = RegQueryStringValue(KeyHand&, sValue)
Call RegCloseKey(KeyHand&)
End Function
Function StripTerminator(ByVal strString As String) As String
Dim intZeroPos As Integer
intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Public Sub SaveSettingEx(HKEY As Long, sPath As String, sValue As String, sData As String)
Dim KeyHand As Long
Call RegCreateKey(HKEY, sPath, KeyHand)
Call RegSetValueEx(KeyHand&, sValue, 0, REG_SZ, ByVal sData, Len(sData))
Call RegCloseKey(KeyHand&)
End Sub
Code for a Form.
Private Sub Command1_Click()
Dim sWinName As String
sWinName = GetSettingEx(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion", "ProductName")
MsgBox "You are running " & sWinName
End Sub
Chris
Jan 12th, 2001, 04:28 AM
Meg, I can't get this in WinNT platform. Why?
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ProductName :confused:
PJB
Jan 12th, 2001, 10:23 AM
I got it to work on Windows 2000 by changing it to this:
(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", "ProductName")
Chris
Jan 12th, 2001, 10:31 AM
Thanks PJB, it great. Finally I learn somethings new from Help and you. :))
PJB
Jan 12th, 2001, 10:53 AM
always happy to help a pompous ass :) , but all i did was plug the NT into what Megatron posted, so if you want to thank someone why not thank him for helping someone of your greatness
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.