Geoff KB Posted August 11, 2006 Report Share Posted August 11, 2006 I'm trying to display the windows version within Excel in a message box when an error occurs.I can find the Excel version with Val(Application.version), but I can't find how to get the Windows version.Can anyone help please?Thanks Quote Link to comment Share on other sites More sharing options...
nellie2 Posted August 11, 2006 Report Share Posted August 11, 2006 I think I might have misunderstood your question... but you could go to start > run and type cmd then OKThat will bring up the command prompt. Just type ver and hit enter, your windows version will be displayedOr you could follow the instructions here, but that involves a registry edit so please make sure you back up your registry before making any changes.Or there is BGinfo from Sysinternals... that can put selected information on the desktop if you wish :) Quote Link to comment Share on other sites More sharing options...
Geoff KB Posted August 14, 2006 Author Report Share Posted August 14, 2006 Thanks but that wasn't what I meant.I have a spreadsheet which will be used by people running various versions of Windows. I'd like my error message box to indicate which version of windows they have, so we can identify errors more easily. I'm using val(Applications.version) for the Excel version, I expected Val(osversion.version) to return the Windows version, but it doesn't.Any other ideas much appreciated.Geoff Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted August 14, 2006 Report Share Posted August 14, 2006 These are just ideas because I don't know much about excel but here is what I seen after a quick look on google. I didn't seem that you could do it unless you use a macro. Here are code examples I got from two different sites.'DeklarationsbereichType OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128End TypeDeclare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _ (ByRef lpVersionInformation As OSVERSIONINFO) As Long'CodemodulSub GetWindowsVersion() Dim myOS As OSVERSIONINFO Dim lngResult As Long Dim strVersion As String myOS.dwOSVersionInfoSize = Len(myOS) lngResult = GetVersionEx(myOS) If myOS.dwPlatformId = 0 Then strVersion = "Windows" ElseIf myOS.dwPlatformId = 1 Then strVersion = "Windows (95, 98 oder ME)" ElseIf myOS.dwPlatformId = 2 Then strVersion = "Windows (NT, 2000, XP oder 2003)" Else strVersion = "Windows" End If MsgBox strVersion & vbCrLf & "Version " & myOS.dwMajorVersion & "." & _ myOS.dwMinorVersion & vbCrLf & "Build " & myOS.dwBuildNumberEnd Suband Dim sAns As String osInfo = System.Environment.OSVersion With osInfo Select Case .Platform Case .Platform.Win32Windows Select Case (.Version.Minor) Case 0 sAns = "Windows 95" Case 10 If .Version.Revision.ToString() = "2222A" Then sAns = "Windows 98 Second Edition" Else sAns = "Windows 98" End If Case 90 sAns = "Windows Me" End Select Case .Platform.Win32NT Select Case (.Version.Major) Case 3 sAns = "Windows NT 3.51" Case 4 sAns = "Windows NT 4.0" Case 5 If .Version.Minor = 0 Then sAns = "Windows 2000" ElseIf .Version.Minor = 1 Then sAns = "Windows XP" ElseIf .Version.Minor = 2 Then sAns = "Windows Server 2003" Else 'Future version maybe update 'as needed sAns = "Unknown Windows Version" End If End Select End Select End With Return sAns End FunctionThe second is VB. I don't know if you can use them but I thought they may help. goodluck Quote Link to comment Share on other sites More sharing options...
Mahbub Posted August 17, 2006 Report Share Posted August 17, 2006 You can use the following function. Modify it according to your requirement.Function GetOS() Dim strComputer, strWMIOS strComputer = "." On Error Resume Next Dim objWmiService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\cimv2") Dim strOsQuery : strOsQuery = "Select * from Win32_OperatingSystem" Dim colOperatingSystems : Set colOperatingSystems = objWMIService.ExecQuery(strOsQuery) Dim objOs Dim strOsVer For Each objOs in colOperatingSystems strWmios = objOs.Caption & " " & objOs.Version Next Select Case True Case InStr(strWmiOS, "2000 Server") > 1 : GetOS = "2KSRV" Case InStr(strWmiOS, "2003, Standard") > 1 : GetOS = "2K3SRV" Case InStr(strWmiOS, "2003, Enterprise") > 1 : GetOS = "2K3ENTSRV" Case InStr(strWmiOS, "2000 Advanced Server") > 1 : GetOS = "2KADVSRV" Case InStr(strWmiOS, "Windows NT") > 1 : GetOS = "NT4" Case InStr(strWmiOS, "Windows 2000") > 1 : GetOS = "W2K" Case InStr(strWmiOS, "Windows XP") > 1 : GetOS = "WXP" Case Else : GetOS = "Unknown" End Select End Function Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.