Click here to Skip to main content
15,921,276 members

Comments by Member 13879661 (Top 3 by date)

Member 13879661 13-Jul-18 3:23am View    
True, I thought of editing it in the installer, but what if the registry gets altered. My application needs this functionality at some specific time.
The application checked for .net framework 4.5 and installs that framework during installation. After studying through some articles i found out that for framework 4.7 the keys (i require to create) are there by default. However I analysed another use case where if some kind of installation/installation is done for higher/lower frameworks they key may/may not be there.
Simple works having it at installation is not best the solution(I may be in correct and suggestions from you would help me get a better resolution :) )
So i thought of getting it done via application.

All users using the app generally are administrators( i agree on the administrator rights parts)

Thank you for all the help so far !
Member 13879661 12-Jul-18 6:11am View    
I need to enable the registry to make the application communicate via TLS1.2. I am not sure if i can do it via configuration files.
Can I ?
Member 13879661 12-Jul-18 5:38am View    
Deleted
Option Explicit

Private Const REG_SZ As Long = 1
Private Const REG_DWORD As Long = 4

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003

'Return values for all registry functions
Private Const ERROR_SUCCESS = 0
Private Const ERROR_NONE = 0

Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_ALL_ACCESS = &H3F


'API Calls for writing to Registry

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
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 RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long


Private Sub SaveValue(hKey As Long, strPath As String, strvalue As String, strData As String)

Dim ret
RegCreateKey hKey, strPath, ret
RegSetValueEx ret, strvalue, 0, REG_DWORD, ByVal strData, Len(strData)
RegCloseKey ret

End Sub

Private Sub QueryValue(sKeyName As String, sValueName As String)

Dim lRetVal As Long
Dim hKey As Long
Dim vValue As Variant
Dim Data As Long
Dim retval As Long
Dim lType As Long
Dim lValue As Long
Dim sValue As String

lRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyName, 0, KEY_QUERY_VALUE, hKey)
retval = RegQueryValueExNULL(hKey, sValueName, 0&, lType, 0&, Data)
If retval <> ERROR_NONE Then MsgBox "The Regisrt Key is not existing exist"
If retval = ERROR_NONE Then
Select Case lType
' Determine strings
Case REG_SZ:
sValue = String(Data, 0)

retval = RegQueryValueExString(hKey, sValueName, 0&, lType, sValue, Data)

If retval = ERROR_NONE Then
vValue = Left$(sValue, Data - 1)
Else
vValue = Empty
End If

' Determine DWORDS
Case REG_DWORD:
retval = RegQueryValueExLong(hKey, sValueName, 0&, lType, lValue, Data)

If retval = ERROR_NONE Then vValue = lValue

Case Else
'all other data types not supported
retval = -1
End Select

MsgBox "The Regisrt Settings exist"

RegCloseKey (hKey)
End If
Call SaveValue(HKEY_LOCAL_MACHINE, "Software\Micr