Results 1 to 3 of 3

Thread: Registry edit help !!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    TZI Transition Date
    Posts
    272

    Registry edit help !!

    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

  2. #2
    Si_the_geek
    Guest
    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:
    VB Code:
    1. Const ERROR_NONE = 0         'all the standard Registry errors
    2. Const ERROR_BADDB = 1
    3. Const ERROR_BADKEY = 2
    4. Const ERROR_CANTOPEN = 3
    5. Const ERROR_CANTREAD = 4
    6. Const ERROR_CANTWRITE = 5
    7. Const ERROR_OUTOFMEMORY = 6
    8. Const ERROR_ARENA_TRASHED = 7
    9. Const ERROR_ACCESS_DENIED = 8
    10. Const ERROR_INVALID_PARAMETERS = 87
    11. Const ERROR_NO_MORE_ITEMS = 259
    12. Const ERROR_INSUFFICIENT_BUFFER = 122
    13. Const ERROR_KEY_DELETED = 1018
    14. Const ERROR_REGISTRY_CORRUPT = 1015
    15.  
    16. Dim lRetVal As Long
    17. lRetVal = RegOpenKeyEx (HKEY_CURRENT_USER, subkey, 0, KEY_WRITE, hregkey)
    18. If lRetVal <> ERROR_NONE Then
    19.  msgbox "error!"
    20. end if

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    TZI Transition Date
    Posts
    272
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width