|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
But it fails, returning a 5 not 6 in the IDE. VB6 on Vista Ultimate PC. Is there a better way? What am I missing? Should it not be =6 rather than >=? Will Windows 7 = 7 ? Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long Private Type OSVERSIONINFOEX dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 wServicePackMajor As Integer wServicePackMinor As Integer wSuiteMask As Integer wProductType As Byte wReserved As Byte End Type Dim osv As OSVERSIONINFOEX osv.dwOSVersionInfoSize = Len(osv) If GetVersionEx(osv) = 1 Then If osv.dwPlatformId = 2 And osv.dwMajorVersion >= 6 Then IsVista = True Else IsVista = False End If End If
Show quote
Hide quote
"Bee" <B**@discussions.microsoft.com> wrote in message GetVersionEx() doesn't necessarily return 1, and if the compatibility mode news:875D9D66-7281-42DE-8E53-CB70308D9B3D@microsoft.com... >I am using this routine to tell if the OS is Vista. > > But it fails, returning a 5 not 6 in the IDE. > VB6 on Vista Ultimate PC. > > Is there a better way? > What am I missing? > Should it not be =6 rather than >=? > Will Windows 7 = 7 ? > > Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" > (lpVersionInformation As OSVERSIONINFOEX) As Long > > Private Type OSVERSIONINFOEX > dwOSVersionInfoSize As Long > dwMajorVersion As Long > dwMinorVersion As Long > dwBuildNumber As Long > dwPlatformId As Long > szCSDVersion As String * 128 > wServicePackMajor As Integer > wServicePackMinor As Integer > wSuiteMask As Integer > wProductType As Byte > wReserved As Byte > End Type > > Dim osv As OSVERSIONINFOEX > > osv.dwOSVersionInfoSize = Len(osv) > > If GetVersionEx(osv) = 1 Then > If osv.dwPlatformId = 2 And osv.dwMajorVersion >= 6 Then > IsVista = True > Else > IsVista = False > End If > End If > is set for the app, it will return the compatibility version instead.
Show quote
Hide quote
"Bee" <B**@discussions.microsoft.com> wrote in message news:875D9D66-7281-42DE-8E53-CB70308D9B3D@microsoft.com... You mean dwMajorVersion is 5? Make sure you're not running in WinXP compatibility mode. GetVersionEx would provide the version >I am using this routine to tell if the OS is Vista. > > But it fails, returning a 5 not 6 in the IDE. > VB6 on Vista Ultimate PC. > > Is there a better way? > What am I missing? > Should it not be =6 rather than >=? > Will Windows 7 = 7 ? > > Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" > (lpVersionInformation As OSVERSIONINFOEX) As Long > > Private Type OSVERSIONINFOEX > dwOSVersionInfoSize As Long > dwMajorVersion As Long > dwMinorVersion As Long > dwBuildNumber As Long > dwPlatformId As Long > szCSDVersion As String * 128 > wServicePackMajor As Integer > wServicePackMinor As Integer > wSuiteMask As Integer > wProductType As Byte > wReserved As Byte > End Type > > Dim osv As OSVERSIONINFOEX > > osv.dwOSVersionInfoSize = Len(osv) > > If GetVersionEx(osv) = 1 Then > If osv.dwPlatformId = 2 And osv.dwMajorVersion >= 6 Then > IsVista = True > Else > IsVista = False > End If > End If > number for WinXP in that case. -- Mike Perhaps the code at this site might help you...
http://vbnet.mvps.org/code/helpers/isos.htm Note that it this site's code is for the compiled version of VB6, so you might have to account for the difference in that version's controls and their Excel equivalents if you choose to try and implement his posted example... but I am guessing that you are more interested in the code itself (the API calls and how they get used). -- Show quoteHide quoteRick (MVP - Excel) "Bee" <B**@discussions.microsoft.com> wrote in message news:875D9D66-7281-42DE-8E53-CB70308D9B3D@microsoft.com... >I am using this routine to tell if the OS is Vista. > > But it fails, returning a 5 not 6 in the IDE. > VB6 on Vista Ultimate PC. > > Is there a better way? > What am I missing? > Should it not be =6 rather than >=? > Will Windows 7 = 7 ? > > Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" > (lpVersionInformation As OSVERSIONINFOEX) As Long > > Private Type OSVERSIONINFOEX > dwOSVersionInfoSize As Long > dwMajorVersion As Long > dwMinorVersion As Long > dwBuildNumber As Long > dwPlatformId As Long > szCSDVersion As String * 128 > wServicePackMajor As Integer > wServicePackMinor As Integer > wSuiteMask As Integer > wProductType As Byte > wReserved As Byte > End Type > > Dim osv As OSVERSIONINFOEX > > osv.dwOSVersionInfoSize = Len(osv) > > If GetVersionEx(osv) = 1 Then > If osv.dwPlatformId = 2 And osv.dwMajorVersion >= 6 Then > IsVista = True > Else > IsVista = False > End If > End If > Forget about the Excel part of my message... I thought I was in a different
newsgroup... you should be able to implement the example as is. -- Show quoteHide quoteRick (MVP - Excel) "Rick Rothstein" <rick.newsNO.SPAM@NO.SPAMverizon.net> wrote in message news:eTGsK8WrJHA.1492@TK2MSFTNGP03.phx.gbl... > Perhaps the code at this site might help you... > > http://vbnet.mvps.org/code/helpers/isos.htm > > Note that it this site's code is for the compiled version of VB6, so you > might have to account for the difference in that version's controls and > their Excel equivalents if you choose to try and implement his posted > example... but I am guessing that you are more interested in the code > itself (the API calls and how they get used). > > -- > Rick (MVP - Excel) > > > "Bee" <B**@discussions.microsoft.com> wrote in message > news:875D9D66-7281-42DE-8E53-CB70308D9B3D@microsoft.com... >>I am using this routine to tell if the OS is Vista. >> >> But it fails, returning a 5 not 6 in the IDE. >> VB6 on Vista Ultimate PC. >> >> Is there a better way? >> What am I missing? >> Should it not be =6 rather than >=? >> Will Windows 7 = 7 ? >> >> Private Declare Function GetVersionEx Lib "kernel32" Alias >> "GetVersionExA" >> (lpVersionInformation As OSVERSIONINFOEX) As Long >> >> Private Type OSVERSIONINFOEX >> dwOSVersionInfoSize As Long >> dwMajorVersion As Long >> dwMinorVersion As Long >> dwBuildNumber As Long >> dwPlatformId As Long >> szCSDVersion As String * 128 >> wServicePackMajor As Integer >> wServicePackMinor As Integer >> wSuiteMask As Integer >> wProductType As Byte >> wReserved As Byte >> End Type >> >> Dim osv As OSVERSIONINFOEX >> >> osv.dwOSVersionInfoSize = Len(osv) >> >> If GetVersionEx(osv) = 1 Then >> If osv.dwPlatformId = 2 And osv.dwMajorVersion >= 6 Then >> IsVista = True >> Else >> IsVista = False >> End If >> End If >> > Ahh compatibility mode is not compatible though.
But that is what it was. Looking at what Rick suggests because I really need to bypass the compatibility thing and see if it is really Vista. Thanks all. Show quoteHide quote "Bee" wrote: > I am using this routine to tell if the OS is Vista. > > But it fails, returning a 5 not 6 in the IDE. > VB6 on Vista Ultimate PC. > > Is there a better way? > What am I missing? > Should it not be =6 rather than >=? > Will Windows 7 = 7 ? > > Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" > (lpVersionInformation As OSVERSIONINFOEX) As Long > > Private Type OSVERSIONINFOEX > dwOSVersionInfoSize As Long > dwMajorVersion As Long > dwMinorVersion As Long > dwBuildNumber As Long > dwPlatformId As Long > szCSDVersion As String * 128 > wServicePackMajor As Integer > wServicePackMinor As Integer > wSuiteMask As Integer > wProductType As Byte > wReserved As Byte > End Type > > Dim osv As OSVERSIONINFOEX > > osv.dwOSVersionInfoSize = Len(osv) > > If GetVersionEx(osv) = 1 Then > If osv.dwPlatformId = 2 And osv.dwMajorVersion >= 6 Then > IsVista = True > Else > IsVista = False > End If > End If > As noted, GetVersionEx will lie to you if you're
running in compatibility mode. If that's OK, then GetVersionEx is fine. If you want to *really* know (without any funny business ;) this is what I use: Private Declare Function LoadLibrary Lib "KERNEL32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long Private Declare Function GetProcAddress Lib "KERNEL32" (ByVal hModule As Long, ByVal lpProcName As String) As Long Private Declare Function FreeLibrary Lib "KERNEL32" (ByVal hLibModule As Long) As Long Private Declare Function GetVersionEx Lib "KERNEL32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Private Declare Function DllGetVersion Lib "shell32" (pdvi As DLLVERSIONINFO) As Long Public Function IsOSVista() As Boolean Dim LRet As Long, hLib As Long, LShl As Long, L2 As Long Dim OSV As OSVERSIONINFO Dim DVI As DLLVERSIONINFO IsOSVista = False On Error Resume Next '--------------------- GetVersionEx ------------------ OSV.dwOSVersionInfoSize = Len(OSV) LRet = GetVersionEx(OSV) If (OSV.dwPlatformId = 2) And (OSV.dwMajorVersion >= 6) Then IsOSVista = True Exit Function End If '------------- check for Vista-only API -------------------- LRet = 0 hLib = LoadLibrary("kernel32.dll") If (hLib <> 0) Then LRet = GetProcAddress(hLib, "GetLocaleInfoEx") L2 = FreeLibrary(hLib) End If If (LRet <> 0) Then IsOSVista = True Exit Function End If '----------------------- shell32 dllgetversion ----------- LRet = 0 hLib = LoadLibrary("shell32.dll") If (hLib <> 0) Then LRet = GetProcAddress(hLib, "DllGetVersion") L2 = FreeLibrary(hLib) End If If (LRet <> 0) Then DVI.cbSize = Len(DVI) LRet = DllGetVersion(DVI) If (LRet = 0) Then If (DVI.dwMajorVersion = 6) And ((DVI.dwBuildNumber > 5000) Or (DVI.dwMinorVersion > 0)) Then IsOSVista = True End If End If End If End Function See here for more info.: http://17slon.com/blogs/gabr/2007/02/four-ways-to-detect-vista.html As for Windows 7, I think that's 6.1. -- Show quoteHide quoteJSWare www.jsware.net jsw***@jsware.net __________________ Please note: JSWare does not accept email from free, commercial "webmail" sources such yahoo, gmail, or hotmail. For further explanation please see: www.jsware.net/jsware/contact.php3#webmail Bee <B**@discussions.microsoft.com> wrote in message news:875D9D66-7281-42DE-8E53-CB70308D9B3D@microsoft.com... > I am using this routine to tell if the OS is Vista. > > But it fails, returning a 5 not 6 in the IDE. > VB6 on Vista Ultimate PC. > > Is there a better way? > What am I missing? > Should it not be =6 rather than >=? > Will Windows 7 = 7 ? > > Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" > (lpVersionInformation As OSVERSIONINFOEX) As Long > > Private Type OSVERSIONINFOEX > dwOSVersionInfoSize As Long > dwMajorVersion As Long > dwMinorVersion As Long > dwBuildNumber As Long > dwPlatformId As Long > szCSDVersion As String * 128 > wServicePackMajor As Integer > wServicePackMinor As Integer > wSuiteMask As Integer > wProductType As Byte > wReserved As Byte > End Type > > Dim osv As OSVERSIONINFOEX > > osv.dwOSVersionInfoSize = Len(osv) > > If GetVersionEx(osv) = 1 Then > If osv.dwPlatformId = 2 And osv.dwMajorVersion >= 6 Then > IsVista = True > Else > IsVista = False > End If > End If >
Show quote
Hide quote
"Bee" <B**@discussions.microsoft.com> wrote in message I need to know the OS when I'm installing my USB drivers. so I use the following code.news:875D9D66-7281-42DE-8E53-CB70308D9B3D@microsoft.com... >I am using this routine to tell if the OS is Vista. > > But it fails, returning a 5 not 6 in the IDE. > VB6 on Vista Ultimate PC. > > Is there a better way? > What am I missing? > Should it not be =6 rather than >=? > Will Windows 7 = 7 ? > > Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" > (lpVersionInformation As OSVERSIONINFOEX) As Long > > Private Type OSVERSIONINFOEX > dwOSVersionInfoSize As Long > dwMajorVersion As Long > dwMinorVersion As Long > dwBuildNumber As Long > dwPlatformId As Long > szCSDVersion As String * 128 > wServicePackMajor As Integer > wServicePackMinor As Integer > wSuiteMask As Integer > wProductType As Byte > wReserved As Byte > End Type > > Dim osv As OSVERSIONINFOEX > > osv.dwOSVersionInfoSize = Len(osv) > > If GetVersionEx(osv) = 1 Then > If osv.dwPlatformId = 2 And osv.dwMajorVersion >= 6 Then > IsVista = True > Else > IsVista = False > End If > End If > The installs are out in the field and I don't want to interact with the Customer. I added the Win 7 after testing it today. Galen Private Declare Function GetVersionExA Lib "kernel32" _ (lpVersionInformation As OSVERSIONINFO) As Integer Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Public Function GetVersNumber() As Long Dim osinfo As OSVERSIONINFO Dim retvalue As Integer osinfo.dwOSVersionInfoSize = 148 osinfo.szCSDVersion = Space$(128) retvalue = GetVersionExA(osinfo) With osinfo Select Case .dwPlatformId Case 1 Select Case .dwMinorVersion Case 0 GetVersNumber = 1 ' Windows 95 Case 10 GetVersNumber = 2 ' Windows 98 Case 90 GetVersNumber = 3 ' Windows 98me End Select Case 2 Select Case .dwMajorVersion Case 0 GetVersNumber = 6 ' Windows NT 3.51 Case 4 GetVersNumber = 7 ' Windows NT 4.0 Case 5 If .dwMinorVersion = 0 Then GetVersNumber = 4 ' Windows 2000 Else GetVersNumber = 5 ' Windows XP End If Case 6 If .dwMinorVersion = 0 Then GetVersNumber = 8 ' Vista Else GetVersNumber = 9 ' Win 7 End If End Select Case Else GetVersNumber = 10 ' Failed End Select frmMain.LabMinor.Caption = "Minor " & .dwMinorVersion frmMain.LabMajor.Caption = "Major " & .dwMajorVersion frmMain.LabPlat.Caption = "Platform " & .dwPlatformId End With End sub
Beep Again
URLDownloadToFile API failing due to disclaimer page Beep Beep OT: Can cause VB6 an error of this kind? Subscript out of range VB 6 on loading a form SQL Server Compact Edition with VB6 VB6 IDE Find doesn't Simple timer uses more and more memory Run-time error '50003': Unexpected error Name of a Callback function |
|||||||||||||||||||||||