Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This code Blew up a Registry, what happened?

Status
Not open for further replies.

fenris

Programmer
May 20, 1999
824
CA
I wrote this small app for one of my users on a compaq deskpro 4000 to make sure the numlock key was on when windows started (Apperently there is no bios option that allows for this). When I installed the app it corrupted the registry really badly. At first i didn't think that it was the program. But after I got the computer up and running again, I tried installing the app again, and it blew up!

So if any one sees anything......

The O/S on the poor computer is win95 B. I tested the app successfully on my machine (win NT 4).

'=============
Option Explicit



' Declare Type for API call:
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type

' API declarations:
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long

Private Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)

Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long

Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long

' Constant declarations:
Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
Const VK_CAPITAL = &H14
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Const VER_PLATFORM_WIN32_NT = 2
Const VER_PLATFORM_WIN32_WINDOWS = 1


Private Sub Form_Load()
Dim o As OSVERSIONINFO
Dim NumLockState As Boolean

o.dwOSVersionInfoSize = Len(o)
GetVersionEx o
Dim keys(0 To 255) As Byte
GetKeyboardState keys(0)

' NumLock handling:
NumLockState = keys(VK_NUMLOCK)
If NumLockState <> True Then 'Turn numlock on
If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '===== Win95
keys(VK_NUMLOCK) = 1
SetKeyboardState keys(0)
ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then '===== WinNT
'Simulate Key Press
keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
'Simulate Key Release
keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY _
Or KEYEVENTF_KEYUP, 0
End If
End If

Label2.Visible = True
Timer1.Enabled = True

End Sub


Private Sub Timer1_Timer()
Timer1.Enabled = False
Unload Me
End Sub


Troy Williams B.Eng.
fenris@hotmail.com

 
Troy, I don't see anything wrong with the code (proper) that could affect the registry... I just wondered why you chose to unload from a timer the first time the timer is called (?!?). Was this a &quot;workaround&quot;? If so, what did it work around?

VCA.gif

Alt255@Vorpalcom.Intranets.com
 
I thought the same thing about the code. I used Installer vise 3.5 to create the installs for the program. I think this may have been the cause...

The idea behind the program was to have it toggle the num lock key on for a cad user because the particular machine doesn't support &quot;boot with numlock on&quot;. This program could have easily executed with out letting the user ever now what was going on. But being the vain programmer that I am I had to throw in a bit of shameless promotion. Basically all the timer does is unload the form after 3 seconds, just long enough to see my credits ;)

Troy Williams B.Eng.
fenris@hotmail.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top