Which Operating System

ted.martin

Registered User.
Local time
Today, 21:31
Joined
Sep 24, 2004
Messages
743
Hi all - I need to run a piece of code to determine whether the user's Operating System is XP or Vista/W7.

Reason: well mt db uses eMail code direct to Outlook and XP requires 'Redemption' to avoid the security warning whereas Vista does not.

I want to select the code lines accordingly for the eMail send process depending which OS we are on.

I hope a simple function will give me a value to use as a flag.

Many thanks:cool:
 
Thanks Wayne - could be the answer. Interestingly I am running Vista Business right now and the msgbox gave ' Windows_NT '

Will be able to try an XP machine tomorrrow. As long as its different I will be able to use this. Thanks
 
Found this

http://malektips.com/xp_dos_0025.html

edited it to put in for 7 and it seems to work...

Code:
@echo off

ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto ver_2003

ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp

ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto ver_2000

ver | find "NT" > nul
if %ERRORLEVEL% == 0 goto ver_nt

ver | find "7" > nul
if %ERRORLEVEL% == 0 goto ver_7

echo Machine undetermined.
goto exit

:ver_2003
:Run Windows 2003-specific commands here.
echo Windows 2003
goto exit

:ver_xp
:Run Windows XP-specific commands here.
echo Windows XP
goto exit

:ver_2000
:Run Windows 2000-specific commands here.
echo Windows 2000
goto exit

:ver_nt
:Run Windows NT-specific commands here.
echo Windows NT
goto exit

:ver_7
:Run Windows 7-specific commands here.
echo Windows 7
goto exit
:exit

On another note.. using simply "Ver" returned "microsoft windows xp" on my xp machine but only "microsoft windows" on my 7 machine...
 
Ray, Ted,

I think you can try:

Dim strOS As String
ShellAndWait("ver > c:\Temp\Version.txt")
Open "C:\Temp\Version.txt" For Input As #1
Line Input #1, strOS
Close #1
If InStr(1, strOS, "Vista") > 1 Then ....

Of course now you need the ShellAndWait, there are examples here.

I didn't realize this was so complicated, I just reread this and even their
own "Ver" function isn't reliable.

Wayne
 
...
However, there must be some easier way. Maybe looking for a specific file? ...

Wayne,

I thought about the specific file, but i doubt he wants to go through that much trouble

There is an api from the mvps site link, that you posted, he could use..

Nice links!
 
WoW - Wayne you have been busy. As long as I get a reference for XP and that Vista and W7 are not the same as XP, I will be able to work with it. Just want to find the easiest and simplest way so that I can use an IF statement to either/or the eMail send code. Thank you very much. With what you have sent should be able to find a method. My XP machine is a work so it will be tomorrow afternoon before I can have a 'play' Will post my favoured solution when I get it.
 
Last edited:
If you add

CLIP< version.doc

to the batch file then version number is in the clipboard.

And you can use VBA in Access to create the batch file and Shell to run it.
 
Ok Guys - Here is my simple solution which does what I need it too. Thanks to ALL of you for your guidance and also to 'Dev' whose code I have cut down for my purposes.

' ******** Code Start ********
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'

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 Declare Function apiGetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As Any) As Long

Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

Public Sub myOS()

Dim OSv As OSVERSIONINFO

OSv.dwOSVersionInfoSize = Len(OSv)
If CBool(apiGetVersionEx(OSv)) Then

With OSv

If .dwPlatformId = VER_PLATFORM_WIN32_NT And .dwMajorVersion = 5 And .dwMinorVersion = 1 Then
myOS = "XP"
MsgBox "The Operating System on this PC is 'XP'", vbInformation, .dwMajorVersion & "." & .dwMinorVersion
Exit Function
End If

If .dwPlatformId = VER_PLATFORM_WIN32_NT And .dwMajorVersion = 6 And .dwMinorVersion = 0 Then ' Think Windows 7 is 6.1
myOS = "Vista"
MsgBox "The Operating System on this PC is 'Vista'", vbInformation, .dwMajorVersion & "." & .dwMinorVersion
Exit Function
End If

End With
End If

' Problem if we get here.
myOS = "STOP" ' i.e. Not XP or Vista
MsgBox "The Operating System on this PC is not 'XP' or 'Vista'", vbExclamation, "Contact Administrator immediately " & OSv.dwMajorVersion & "." & OSv.dwMinorV

End Sub
 
Last edited:
Might want to do

Code:
If .dwPlatformId = VER_PLATFORM_WIN32_NT And .dwMajorVersion = 6 Then
    MsgBox "Vista or Windows 7"
    End If
 
Thanks - I think if i used the .dwminorversion too I could differentiate ebwteen Vista a W7 as
Windows Vista 6.0
Windows 7 6.1
except that as I don't have W7 - I will have to wait and see. Thanks though. Since posting this I have incorporarted .dwminorversion to differentiate between W2000 and XP both of which are .dwMajorVersion =5
 

Users who are viewing this thread

Back
Top Bottom