PDA

Click to See Complete Forum and Search --> : Registry edit help !!


MJBNET
Nov 20th, 2001, 08:19 AM
I am trying to edit the key to turn off images in IE, from a macro in Excel...It has no effect, no errors, no new entrys, nothin. I am sure it is the right key 'cause I see it change when I turn it off from IE advanced options... I copied most of the code right out of the API guide on this site... plz help :}




This is the code
****************************************************

'declarations

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 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

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
____________________________________________________

Sub AA()

Dim subkey As String
Dim stringbuffer As String
Dim hregkey As Long

subkey = "Software\Microsoft\Internet Explorer\Main\Display Inline Images"
stringbuffer = "no" & vbNullChar

RegOpenKeyEx HKEY_CURRENT_USER, subkey, 0, KEY_WRITE, hregkey

RegSetValueEx hregkey, "subkey", 0, REG_SZ, ByVal stringbuffer, Len(stringbuffer)

RegCloseKey hregkey

End Sub

Si_the_geek
Nov 20th, 2001, 09:59 AM
do you have definitions for those bold bits, eg: HKEY_CURRENT_USER ?

if you do have them, you can check for errors on each statement like this:

Const ERROR_NONE = 0 'all the standard Registry errors
Const ERROR_BADDB = 1
Const ERROR_BADKEY = 2
Const ERROR_CANTOPEN = 3
Const ERROR_CANTREAD = 4
Const ERROR_CANTWRITE = 5
Const ERROR_OUTOFMEMORY = 6
Const ERROR_ARENA_TRASHED = 7
Const ERROR_ACCESS_DENIED = 8
Const ERROR_INVALID_PARAMETERS = 87
Const ERROR_NO_MORE_ITEMS = 259
Const ERROR_INSUFFICIENT_BUFFER = 122
Const ERROR_KEY_DELETED = 1018
Const ERROR_REGISTRY_CORRUPT = 1015

Dim lRetVal As Long
lRetVal = RegOpenKeyEx (HKEY_CURRENT_USER, subkey, 0, KEY_WRITE, hregkey)
If lRetVal <> ERROR_NONE Then
msgbox "error!"
end if
;)

MJBNET
Nov 20th, 2001, 12:18 PM
I finally got it & it works great running from Excel as a macro.
tks for the error stuff !

this is the code I inserted...it maybe be of help to someone else :}
____________________________________________________
Public 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

Public 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

Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long) As Long

Public Const HKEY_CURRENT_USER = &H80000001
Public Const KEY_WRITE = &H20006
Public Const REG_SZ = 1
____________________________________________________

Sub AAAA()

Dim HKEY As Long ' receives handle to the registry key
Dim SUBKEY As String ' name of the subkey open
Dim VALUETOSET As String ' the value to put into the registry
Dim KEYNAME As String ' the name of the registry item to change
Dim RETVAL As Long ' return value

'BEGIN TURN OFF MULTIMEDIA IN INTERNET EXPLORER REG
'***************************************************************************************
' SET NAME & OPEN KEY
SUBKEY = "Software\Microsoft\Internet Explorer\Main"
RETVAL = RegOpenKeyEx(HKEY_CURRENT_USER, SUBKEY, 0, KEY_WRITE, HKEY)
'Check errors
If RETVAL <> 0 Then ' error during open
Debug.Print "Error opening registry key -- aborting."
End ' terminate the program
End If
'SET VALUE TO "no" & WRITE TO REG
'Note the use of ByVal in the second-to-last parameter because we are passing a string.
VALUETOSET = "no" & vbNullChar ' the terminating null is necessary
KEYNAME = "Display Inline Images"
RETVAL = RegSetValueEx(HKEY, KEYNAME, 0, REG_SZ, ByVal VALUETOSET, Len(VALUETOSET))
KEYNAME = "Play_Animations"
RETVAL = RegSetValueEx(HKEY, KEYNAME, 0, REG_SZ, ByVal VALUETOSET, Len(VALUETOSET))
KEYNAME = "Play_Background_Sounds"
RETVAL = RegSetValueEx(HKEY, KEYNAME, 0, REG_SZ, ByVal VALUETOSET, Len(VALUETOSET))
KEYNAME = "Display Inline Videos"
RETVAL = RegSetValueEx(HKEY, KEYNAME, 0, REG_SZ, ByVal VALUETOSET, Len(VALUETOSET))
'CLOSE THE REG KEY
RETVAL = RegCloseKey(HKEY)
'***************************************************************************************
'END TURN OFF MULTIMEDIA IN INTERNET EXPLORER REG

End Sub