-
hi,
Im trying to use the GetVersionEx API to get the windows version. My question is how do I know if the OS is windows2000.
got this from http://www.vbapi.com:
if the return value is 0 then
Windows 3.x is running, using the Win32s pseudo-32-bit enhancements.
if the return value is 1 then
Windows 95 or 98 is running.
if the return value is 2 then
Windows NT is running.
When I tried this on a win2000 system the return value was 2.
Is that correct? and can I go ahead and work based on this return value???
Thanx in advance.
-
Win2000 is basically WinNT 5
So this means "officially" it does return the same as NT did.
If you want to specifically check you will need to look at other information to confirm if its NT or Win2000... the same as if you were trying to determine if it was NT 3 or NT 4 etc
Can't help you on the exact code.. .but have a dig around the registry.
-
You can also retreive the OS from the registry...i'm not 100% sure about win2k though.
Code:
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
Private Const REG_BINARY = 3
Private Const REG_DWORD = 4
Private Const ERROR_SUCCESS = 0&
Private 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
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" _
Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey _
As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private 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
Private Function getstring(Hkey As Long, strPath As String, strValue As String)
Dim keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
r = RegOpenKey(Hkey, strPath, keyhand)
lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
getstring = Left$(strBuf, intZeroPos - 1)
Else
getstring = strBuf
End If
End If
End If
End Function
Public Sub Command1_Click()
Text1.Text = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion", "ProductName")
End Sub
That's alot of code and you might wanna stick to the GetVersionEx API, but i'm not sure how it would work for Win2k.
Gl,
D!m
PS. have a look around the registry for any other keys that you can retreive that could help you.
#500
[Edited by Dim on 10-04-2000 at 12:57 AM]
-
thanx Gen-x and Dim.
The reason I'm trying to do this is that I need to copy my .scr file to the windows folder. Under win95 I have to copy it to the WINDOWS folder. But under win2000 the folder is WINNT. So I was trying to get the version so that I can copy the .scr file to the correct folder.
So If win2000 is NT5 then the folder will be WINNT, right?
So it should be enuf if I use the getVersionEx and the copy the .scr file either to the WINDOWS or WINNT folder depending on the OS, right?
Thanx again. :-)
-
You may have a problem if a person put Windows2000 in the 'Windows' folder instead of 'WinNT' or if a the person using Win95 use the 'Win95' folder instead of 'Windows' then you rather use the GetWindowsDirectoryA API
Code:
Option Explicit
Private Const gStrNULL = ""
Private Const gStrSEP_URLDIR = "/"
Private Const gintMAX_SIZE = 255
Private Const gStrSEP_DIR = "\"
Private Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Function GetWindowsDir() As String
Dim strBuf As String
strBuf = Space$(gintMAX_SIZE)
'
' Obtient le dossier de Windows et ajuste le tampon à la
' longueur exacte renvoyée, et ajoute un séparateur de
' dossier (barre oblique inverse) si l'API n'a rien renvoyé.
'
If GetWindowsDirectory(strBuf, gintMAX_SIZE) > 0 Then
strBuf = StripTerminator$(strBuf)
AddDirSep strBuf
GetWindowsDir = strBuf
Else
GetWindowsDir = gStrNULL
End If
End Function
Public 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 Function AddDirSep(strPathName As String) As String
If Right(Trim(strPathName), Len(gStrSEP_URLDIR)) <> gStrSEP_URLDIR And _
Right(Trim(strPathName), Len(gStrSEP_DIR)) <> gStrSEP_DIR Then
strPathName = RTrim$(strPathName) & gStrSEP_DIR
AddDirSep = strPathName
End If
End Function
-
Ok, Im sorry this is what I should have asked
The reason I'm trying to do this is that I need to copy my .scr file to the windows folder.
Under win95 I have to copy it to the WINDOWS folder. But under win2000 the folder is WINNT.
So I was trying to get the version so that I can copy the .scr file to the correct folder.
So If win2000 is NT5 then the folder will be WINNT, right?
So it should be enuf if I use the getVersionEx to get the OS version and then get the Windows folder
using the GetWindowsDirectory and then finally copy the .scr file to the retreived folder
depending on the OS, right?
Thanx again.
-
And if you want the System32 folder, add this code
Code:
Private Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Function GetWindowsSysDir() As String
Dim strBuf As String
strBuf = Space$(gintMAX_SIZE)
'
' Get the system dir, and add \ if is missing.
'
If GetSystemDirectory(strBuf, gintMAX_SIZE) > 0 Then
strBuf = StripTerminator(strBuf)
AddDirSep strBuf
GetWindowsSysDir = strBuf
Else
GetWindowsSysDir = gStrNULL
End If
End Function
-
There's a great library; Stamina form Microdexterity that provides you with such info easily...
D
-
thanx Dragev, will check it!