mccashinb
Feb 28th, 2001, 06:04 AM
When running my app I want to check the registry for
a test key to see if it is the first time it has been run.
If this is not found, I want to create the key.
If the key does not exist, it creates a new key called
ishere under check when I actually want it to create
a string under the check key containing "Hello".
I am using the following code:
Private Function GetKeys()
Dim testreturn As Integer
Dim real As String
Dim encr As String
Dim subkeytest As String
Dim key_Return As Long
Dim hregkey As Long
Dim secattr As SECURITY_ATTRIBUTES
Dim neworused As Long
Dim stringbuffer As String
HKEY_LOCAL_MACHINE = &H80000002
KEY_READ = &H20019
KEY_WRITE = &H20006
secattr.nLength = Len(secattr)
secattr.lpSecurityDescriptor = 0
secattr.bInheritHandle = 1
subkeytest = "\SOFTWARE\co_name\sysname\010000\check\ishere"
stringbuffer = "Hello" + vbNullChar
REG_SZ = 1
'Check for test key
key_Return = RegOpenKeyEx(HKEY_LOCAL_MACHINE, subkeytest, 0, KEY_READ, hregkey)
If key_Return <> 0 Then
'Error , key not opened - Tell the user
MsgBox "This appears to be the first time this program has been run." + vbCrLf + "Please wait while the setup sets up!", vbOKOnly, "First Run"
'Create the keys needed
key_Return = RegCreateKeyEx(HKEY_LOCAL_MACHINE, subkeytest, 0, "", 0, KEY_WRITE, secattr, hregkey, neworused)
If key_Return <> 0 Then
'Create key failed
MsgBox "Could not initialize application" + vbCrLf + "Please contact .....etc.", vbCritical, "Initialization Error - Oops!!"
Else
'Success - now set value
key_Return = RegSetValueEx(HKEY_LOCAL_MACHINE, "SystemTest", 0, REG_SZ, ByVal stringbuffer, Len(stringbuffer))
End If
'Close the other key
retval = RegCloseKey(hKeyreg)
'Give default values
Else
'Get values of data keys
End If
End Function
a test key to see if it is the first time it has been run.
If this is not found, I want to create the key.
If the key does not exist, it creates a new key called
ishere under check when I actually want it to create
a string under the check key containing "Hello".
I am using the following code:
Private Function GetKeys()
Dim testreturn As Integer
Dim real As String
Dim encr As String
Dim subkeytest As String
Dim key_Return As Long
Dim hregkey As Long
Dim secattr As SECURITY_ATTRIBUTES
Dim neworused As Long
Dim stringbuffer As String
HKEY_LOCAL_MACHINE = &H80000002
KEY_READ = &H20019
KEY_WRITE = &H20006
secattr.nLength = Len(secattr)
secattr.lpSecurityDescriptor = 0
secattr.bInheritHandle = 1
subkeytest = "\SOFTWARE\co_name\sysname\010000\check\ishere"
stringbuffer = "Hello" + vbNullChar
REG_SZ = 1
'Check for test key
key_Return = RegOpenKeyEx(HKEY_LOCAL_MACHINE, subkeytest, 0, KEY_READ, hregkey)
If key_Return <> 0 Then
'Error , key not opened - Tell the user
MsgBox "This appears to be the first time this program has been run." + vbCrLf + "Please wait while the setup sets up!", vbOKOnly, "First Run"
'Create the keys needed
key_Return = RegCreateKeyEx(HKEY_LOCAL_MACHINE, subkeytest, 0, "", 0, KEY_WRITE, secattr, hregkey, neworused)
If key_Return <> 0 Then
'Create key failed
MsgBox "Could not initialize application" + vbCrLf + "Please contact .....etc.", vbCritical, "Initialization Error - Oops!!"
Else
'Success - now set value
key_Return = RegSetValueEx(HKEY_LOCAL_MACHINE, "SystemTest", 0, REG_SZ, ByVal stringbuffer, Len(stringbuffer))
End If
'Close the other key
retval = RegCloseKey(hKeyreg)
'Give default values
Else
'Get values of data keys
End If
End Function