Check Windows Version

Talk2Tom11

Well-known member
Joined
Feb 22, 2004
Messages
144
Location
Westchester, NY
I am having a little problem... I wrote a code to check if the computer is running windows xp, and if it is, then go through to the program, if not then give a messagebox error. But the problem is, if you are not running it, and wait a few seconds after the messagebox has been displayed, the main form will popup. here is my code

Code:
Private Sub Start_Check_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myKey As Microsoft.Win32.RegistryKey
        Dim strLocation As String
        Dim strKey As String

        strLocation = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
        strKey = "ProductName"

        myKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(strLocation)
        If myKey.GetValue(strKey) = "Microsoft Windows XPh" Then
            fL.ShowDialog(Me)
        Else
            MessageBox.Show("You are Running " & myKey.GetValue(strKey) & ".  " & " You Must Run Windows XP or Higher", "Windows Version Check", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.Close()
        End If
        myKey.Close()
    End Sub
 
Is that the first thing that the application does? If so...

It looks like this code is from a form. Try moving it to a Sub Main in a module and do something like this:

Code:
If XP then
    load your form
End If

This means that the form will only be loaded if the user is running XP.
 
Why are you limiting your users to Windows XP?

Windows XP (Win ver 5.1) is almost the same version as Windows 2000 (Win ver 5.0), and youre not likely to have a very large user base if you only use XP.
 
I know that it is limiting a lot of people... I am not going to end up with only xp user to have access, I am just using this as a sample
 
hmm..well hope this helps.Coded in Vb6 by me.
Function GetAttributes(Filename As String)
On Error Resume Next
Dim Result As String, Attribte As Long
Attribte = GetAttr(Filename)
If Attribte And vbHidden Then
Result = MsgBox("This program is for Win98", vbExclamation, "Error")
ElseIf Dir(Filename) = Empty Then
Result = MsgBox("This program is for Win95", vbExclamation, "Error")
Else
Result = MsgBox("This program is for WinXP", vbExclamation, "Error")
End If
End
End Function
Private Sub Form_Load()
Call GetAttributes("C:\autoexec.bat")
End Sub
 
You could use the environment class to find the version - may be a bit easier (XP is version 5.1)
Code:
        If Environment.OSVersion.Version.Major = 5 AndAlso Environment.OSVersion.Version.Minor = 1 Then
            we are XP
End If
 
the fact of checking if it is xp or not is not my problem... I am having a problem with, even though the messagebox pops up when it is not xp, the program still opens and I dont know what I did in my code to cause that
 
What do you mean? The code up top is what I used... and the checking part works... but when it isnt the right version, it gives the messagebox, but also eventually goes into the app.
 
try this ....
Code:
    Private Sub Start_Check_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim version As Double = Environment.OSVersion.Version.Major & "." & Environment.OSVersion.Version.Minor
        Dim OperatingSystem As String = Environment.OSVersion.Platform.ToString

        If OperatingSystem = "Win32NT" AndAlso version = 5.1 Then
            Console.WriteLine("You are running Windows XP")
            /// let application run
        Else
            MessageBox.Show("You are running an Invalid version of OS , this Application will now terminate" _
            , Convert.ToString(OperatingSystem & " - " & version), MessageBoxButtons.OK, MessageBoxIcon.Error)
            MyBase.Close()
        End If

    End Sub
 
Last edited by a moderator:
Back
Top