Re: Modifying the registry:
Hi,
I have been trying to use this example to modify the security settings in ms excel as follows:
Call CreateKeys(HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Office\11.0\Excel\Security", "Level", REG_DWORD, "4")
Although I can write to REG_SZ, REG_DWORD does not work. I assume this is some sort of lock to prevent VBA from altering the security settings to protect against malicious code. Is this correct?
Re: Modifying the registry:
You may be correct, however there are methods to get around it. There are API and constants available that you can use to change the security settings so you enter data into the registry.
Hope this Helps
Jenova
Re: Modifying the registry:
Check out these constants
VB Code:
Public Const REG_NONE As Long = 0
Public Const REG_SZ As Long = 1
Public Const REG_EXPAND_SZ As Long = 2
Public Const REG_BINARY As Long = 3
Public Const REG_DWORD As Long = 4
Public Const REG_LINK As Long = 6
Public Const REG_MULTI_SZ As Long = 7
Public Const REG_RESOURCE_LIST As Long = 8
Re: Modifying the registry:
Thank you (this is the first post I have had a reply to so it is quite exciting).
I have managed to modify the part of the registry in question using some other code. I would include it in this post but I get the impression that what I am doing is a little contentious and that you don't want exact details on how to modify the security setting on this forum. I can understand and respect that.
The code I used to do this all resides in a module and uses:
Declare Function RegCreateKeyEx& Lib "advapi32.dll"
Declare Function RegSetValueEx& Lib "advapi32.dll" (uses lpDataBuff as Any)
Declare Function RegCloseKey& Lib "advapi32.dll"
And it works fine. The thing is that I am now really curious about the code given in the example above because I know these settings can be modified. There is no block to prevent it. I also know that the code given can modify Reg_SZ and can be used to read the value that I want to change. But I just can't get it to work.
I have used the public constants given but it still only operates when I use REG_SZ. I even checked out another constant (Public Const HKEY_CURRENT_USER = &H80000001).
The thing I just can't fathom is why it works with REG_SZ and not with REG_DWORD.
Can you give me any more clues?
Re: Modifying the registry:
Sorry, I misread your problem, the error was because inside the class it checks to see whether you are passing an integer with the DWORD or a string, and accidently we were passing a string instead.
VB Code:
Option Explicit
Dim reg As New cRegistry
Private Sub Form_Load()
Debug.Print (GetKeys(HKEY_CURRENT_USER, "Software\Game\Settings", "ScreenHeight"))
Debug.Print (CreateKeys(HKEY_CURRENT_USER, "Software\Game\Settings", "ScreenHeight", reg_dword, 700))
End Sub
Private Function GetKeys(HKey As String, Section As String, ValueKey As String) As String
reg.ClassKey = HKey
reg.SectionKey = Section
reg.ValueKey = ValueKey
GetKeys = reg.Value
End Function
Private Function CreateKeys(HKey As String, SectionKey As String, ValueKey As String, Valuetype As String, Value As String) As Boolean
reg.ClassKey = HKey
reg.SectionKey = SectionKey
reg.CreateKey
reg.Valuetype = Valuetype
reg.ValueKey = ValueKey
If IsNumeric(Value) Then
reg.Value = CInt(Value)
Else
reg.Value = Value
End If
CreateKeys = (reg.Value = Value)
End Function
Private Sub Form_Unload(Cancel As Integer)
Set cRegistry = Nothing
End Sub
This is MUCH better code, and I think you will understand it better. I sucked pretty bad at coding when I wrote this, and I didnt even use the functions to return anything :sick:
Anywho, if you have troubles, drop a message right here :thumb:
Re: Modifying the registry:
Quote:
Originally Posted by GMWhite
Hi,
I have been trying to use this example to modify the security settings in ms excel as follows:
Call CreateKeys(HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Office\11.0\Excel\Security", "Level", REG_DWORD, "4")
Although I can write to REG_SZ, REG_DWORD does not work. I assume this is some sort of lock to prevent VBA from altering the security settings to protect against malicious code. Is this correct?
You're sending REG_DWORD a string - try sending it a numeric:
Call CreateKeys(HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Office\11.0\Excel\Security", "Level", REG_DWORD, 4)
Re: Modifying the registry:
I have it working. Thanks all for your help.