Results 1 to 13 of 13

Thread: [Resolved] Variable resets itself

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    [Resolved] Variable resets itself

    Hello,
    I have written an installer to install drivers and an application package. It's a simple program that launches other installers. At issue is the OS variable. This runs fine on an XP machine, but on W7 64 bit, I get screwy behavior. Upon load, the OS variable is initialized to 0. The OS is polled and OS is set to either 32 or 64, for 32 bit or 64 bit. The type of OS is then displayed in the title of the form, and on both XP and W7, it displays correctly. That is, 32 bit for my 32 bit XP machine and 64 bit for my co-workers 64 bit W7 machine. Now, when the Ok button is clicked, the OS variable is evaluated and if it's 0, the error message "Unable to determine OS bit width..." appears. Well, the error message should not appear at all because OS = 32 or 64, but on the W7 machine, it does appear. How in the world could OS be getting reset to 0?
    Driving me nuts!!
    Thanks.


    Code:
    Imports Microsoft.Win32
    Public Class Form1
        Private OS As Integer
    
        Private Sub BtnCancel_Click(sender As System.Object, e As System.EventArgs) Handles BtnCancel.Click
            Me.Close()
        End Sub
    
        Private Sub BtnOk_Click(sender As System.Object, e As System.EventArgs) Handles BtnOk.Click
            Me.Hide()
    
            If rbtnDriversOnly.Checked Or rbtnDriversAndApp.Checked Then
                If OS = 0 Then
                    MessageBox.Show("Unable to determine OS bit width.  Please manually install driver by browsing to the USB Drivers " _
                        & "folder on the CD and running DPInst_x86 (for 32 bit OS) or DPInst_x64 (for 64 bit OS).", "Error", _
                        MessageBoxButtons.OK, MessageBoxIcon.Error)
                Else
                    Try
                        Select Case OS
                            Case 32
                                Shell("USB Drivers\DPInst_x86.exe", AppWinStyle.NormalFocus, True) 'launch, normal window, wait for completion
                            Case 64
                                Shell("USB Drivers\DPInst_x64.exe", AppWinStyle.NormalFocus, True) 'launch, normal window, wait for completion
                            Case Else
                        End Select
                    Catch ex As Exception
                        MessageBox.Show("Error launching USB Driver installation.  Please manually install driver by browsing to the USB Drivers " _
                            & "folder on the CD and running DPInst_x86 (for 32 bit OS) or DPInst_x64 (for 64 bit OS).", "Error", _
                            MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try
                End If
            End If
    
            If rbtnDriversAndApp.Checked Or rbtnAppOnly.Checked Then
                Try
                    Shell("Application.exe", AppWinStyle.NormalFocus, False) 'launch application, normal window, don't wait for completion
                Catch ex As Exception
                    MessageBox.Show("Unable to launch Application.exe.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
            End If
    
            Me.Close()
        End Sub
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            rbtnDriversOnly.Checked = False
            rbtnDriversAndApp.Checked = False
            rbtnAppOnly.Checked = False
            BtnOk.Enabled = False
            BtnCancel.Enabled = True
            rbtnDriversOnly.Focus()
            OS = 0 'init to no detected OS
            Try
                If Registry.LocalMachine.OpenSubKey("Hardware\Description\System\CentralProcessor\0").GetValue("Identifier").ToString.Contains("x86") Then
                    OS = 32 '32 bit OS
                End If
                If Registry.LocalMachine.OpenSubKey("Hardware\Description\System\CentralProcessor\0").GetValue("Identifier").ToString.Contains("x64") Then
                    OS = 64 '64 bit OS
                End If
            Catch ex As Exception
            End Try
            If OS <> 0 Then 'if OS bit width detected, show it
                Me.Text = "USB Driver & App Installer - (" & OS.ToString & " Bit OS)"
            End If
            Timer1.Enabled = True
        End Sub
    
        Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
            If rbtnDriversOnly.Checked Or rbtnDriversAndApp.Checked Or rbtnAppOnly.Checked Then
                BtnOk.Enabled = True
            Else
                BtnOk.Enabled = False
            End If
        End Sub
    End Class
    Last edited by rickford66; Aug 21st, 2012 at 06:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width