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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change registry from a vba function 1

Status
Not open for further replies.

pranay7777

Programmer
Sep 25, 2001
14
0
0
US
can we change registry from a vba function...???if yes how...
 
If you look up "Registry Keyword Summary" in help, you will see the functions you can use... Terry M. Hoey
 
thanx for responding...
i just want to edit
HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\Engines\Text\DisabledExtensions
and add ,cmd at the end in this registry file...
can u help me out with some sample code...access help is helpful but not much...this is my first time with registry...
thanx again...
 
I haven't done it in over seven years and don't have that source code still. The only way I could help you any more is if I read the help file and figured it out for you. Terry M. Hoey
 
may not be the best way...but works for me...

thanx a lot for helping..
Option Compare Database
Public Const REG_SZ As Long = 1
Public Const REG_DWORD As Long = 4

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

Public Const ERROR_NONE = 0
Public Const ERROR_BADDB = 1
Public Const ERROR_BADKEY = 2
Public Const ERROR_CANTOPEN = 3
Public Const ERROR_CANTREAD = 4
Public Const ERROR_CANTWRITE = 5
Public Const ERROR_OUTOFMEMORY = 6
Public Const ERROR_ARENA_TRASHED = 7
Public Const ERROR_ACCESS_DENIED = 8
Public Const ERROR_INVALID_PARAMETERS = 87
Public Const ERROR_NO_MORE_ITEMS = 259

Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_ALL_ACCESS = &H3F

Public Const REG_OPTION_NON_VOLATILE = 0

Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
"RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
As Long, phkResult As Long, lpdwDisposition As Long) As Long
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
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
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
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
Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
String, ByVal cbData As Long) As Long
Declare Function RegSetValueExLong Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, _
ByVal cbData As Long) As Long

Private Sub CreateNewKey(sNewKeyName As String, lPredefinedKey As Long)
Dim hNewKey As Long 'handle to the new key
Dim lRetVal As Long 'result of the RegCreateKeyEx function

lRetVal = RegCreateKeyEx(lPredefinedKey, sNewKeyName, 0&, _
vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, _
0&, hNewKey, lRetVal)
RegCloseKey (hNewKey)
End Sub

Private Sub SetKeyValue(sKeyName As String, sValueName As String, _
vValueSetting As Variant, lValueType As Long)
Dim lRetVal As Long 'result of the SetValueEx function
Dim hKey As Long 'handle of open key

'open the specified key
lRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyName, 0, _
KEY_SET_VALUE, hKey)
lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
RegCloseKey (hKey)
End Sub

Function CreateDisabledExtensionsValue()
CreateNewKey "Software\Microsoft\Jet\4.0\Engines\Text", HKEY_LOCAL_MACHINE
SetKeyValue "Software\Microsoft\Jet\4.0\Engines\Text", "DisabledExtensions", "!txt,csv,tab,asc,htm,html,cpd", REG_SZ
SetKeyValue "Software\Microsoft\Jet\4.0\Engines\Text", "Extensions", "txt,csv,tab,asc,htm,html,cpd", REG_SZ
End Function

Public Function SetValueEx(ByVal hKey As Long, sValueName As String, _
lType As Long, vValue As Variant) As Long
Dim lValue As Long
Dim sValue As String
Select Case lType
Case REG_SZ
sValue = vValue & Chr$(0)
SetValueEx = RegSetValueExString(hKey, sValueName, 0&, _
lType, sValue, Len(sValue))
Case REG_DWORD
lValue = vValue
SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, _
lType, lValue, 4)
End Select
End Function


 
Alternatively to this honorable though a little bit complicated API function there is a code library for ACCESS 2000 available that makes it extremely simple to write into and read from the Registry ("ACCESS Registry Wizard"). I purchased it last year for $ 90,-, I think I found it at winsite.
 
Can some one Please explain how to change registry values to 0 in HEXADECIMAL...

Sample code will really help ....

Thanks Taha
thamiral@uwo.ca
 
additionally ... How do see if certain regisry entires are there and check them for their values?

Thanks Taha
thamiral@uwo.ca
 
why not just tell us what setting it is you are tring to change, there may be a much easier way of doing it then changing the registry... i know one setting (windows in task bar) has a regestry setting, but there are much easier ways of making that false...

just an idea....

--James junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Hello again Junior 1544 , the setting i wated to change was the one outlined in

thread705-323980 already answered it there ..... thanks..... now i am just wondering if there is a way to run that code First thing .... or a way to write the autoexec using VB

Thanks Taha
thamiral@uwo.ca
 
Sorry to disappoint you, but:
It is not necessary to use API function calls for such a simple action as changing the registry settings!
You should simply use the Windows Script Host (WSH). You will find the complete documentation microsoft.com.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top