How can i make my app open a registry file (one that i make) the first time it is opened and then have the apps look to to the registry and see that is already has the information or key or string and not open again?
Printable View
How can i make my app open a registry file (one that i make) the first time it is opened and then have the apps look to to the registry and see that is already has the information or key or string and not open again?
Gl,Code:Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_DYN_DATA = &H80000006
Private Const REG_SZ = 1
Private Const REG_BINARY = 3
Private Const REG_DWORD = 4
Private Const ERROR_SUCCESS = 0&
Private Declare Function RegSetValueEx Lib "advapi32.dll"_
Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal_
lpValueName As String, ByVal Reserved As Long, ByVal dwType_
As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll"_ Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey_
As String, phkResult As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" _
Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey _
As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName _
As String, ByVal lpReserved As Long, lpType As Long, lpData _
As Any, lpcbData As Long) As Long
Private Function getstring(Hkey As Long, strPath As String, strValue As String)
Dim keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
r = RegOpenKey(Hkey, strPath, keyhand)
lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
getstring = Left$(strBuf, intZeroPos - 1)
Else
getstring = strBuf
End If
End If
End If
End Function
'in this example i will make sure that the network logon username is Dim
'you simply have to change the location where the registry
'value should be checked and changed if needed.
Private Sub Command1_Click()
Dim regvalue As String
regvalue = getstring(HKEY_LOCAL_MACHINE, "Network\Logon", "username")
If regvalue = "Dim" Then
Exit Sub
Else
Shell {"C:\my program\registry.reg")
End If
End Sub
D!m
#600
[Edited by Dim on 11-18-2000 at 02:49 PM]