Change value in Registry of Windows with program 
Author Message
 Change value in Registry of Windows with program

Hall all!

How can I change a value in the registry, e.g. the name of the templatespath
of Word or of the sharedteplatespath?

Thank!

--
Dr. Michel Giraud
F.G. Theis KWW GmbH
Tel:( 02331) 693 276



Thu, 12 Jun 2003 03:51:46 GMT  
 Change value in Registry of Windows with program

Michel

Put the following program in a standard module and change the key and values to your required string values.

Regards
Venkata Krishna

_________________________________________________________________________________
Option Explicit

Public Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
End Type

Public Const HKEY_LOCAL_MACHINE = &H80000002                                'Public Const HKEY_CURRENT_USER = &H80000001

Public Const READ_CONTROL = &H20000
Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const SYNCHRONIZE = &H100000
Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))

Public Const REG_SZ = 1                         ' Unicode nul terminated string

Public 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, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition 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         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Dim hKey As Long
Dim SecAttr As SECURITY_ATTRIBUTES
Dim strSubKey As String
Dim lngNewExisting As Long
Dim strKeyValue As String
Dim hRetVal As Long

Sub SetRegistry()
    strSubKey = "SOFTWARE\Microsoft\Office\8.0\Common\FileNew\LocalTemplates"
    strKeyValue = "C:\Program Files\Microsoft Office\Templates" & vbNullChar

    SecAttr.nLength = Len(SecAttr)
    SecAttr.lpSecurityDescriptor = 0
    SecAttr.bInheritHandle = True

    hRetVal = RegCreateKeyEx(HKEY_LOCAL_MACHINE, strSubKey, 0, "", 0, KEY_WRITE, SecAttr, hKey, lngNewExisting)
    If hRetVal = 0 Then
        hRetVal = RegSetValueEx(hKey, "(Default)", 0, REG_SZ, ByVal strKeyValue, Len(strKeyValue))
        hRetVal = RegCloseKey(hKey)
    End If
End Sub


Quote:
> Hall all!

> How can I change a value in the registry, e.g. the name of the templatespath
> of Word or of the sharedteplatespath?

> Thank!

> --
> Dr. Michel Giraud
> F.G. Theis KWW GmbH
> Tel:( 02331) 693 276




Sun, 15 Jun 2003 02:04:34 GMT  
 Change value in Registry of Windows with program

Venkata,

First of all thank you for your code, it goes.

I have three other questions:
    1) How can I read a value in the registry (for instance the name of the RegisteredOwner)?
    2) How can I install with a VBA Program digitale certificate for macro (for instance for excel)

Best regards

Michel

--
Dr. Michel Giraud
F.G. Theis KWW GmbH
Tel:( 02331) 693 276


  Michel

  Put the following program in a standard module and change the key and values to your required string values.

  Regards
  Venkata Krishna

  _________________________________________________________________________________
  Option Explicit

  Public Type SECURITY_ATTRIBUTES
          nLength As Long
          lpSecurityDescriptor As Long
          bInheritHandle As Long
  End Type

  Public Const HKEY_LOCAL_MACHINE = &H80000002                               'Public Const HKEY_CURRENT_USER = &H80000001

  Public Const READ_CONTROL = &H20000
  Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
  Public Const KEY_SET_VALUE = &H2
  Public Const KEY_CREATE_SUB_KEY = &H4
  Public Const SYNCHRONIZE = &H100000
  Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))

  Public Const REG_SZ = 1                         ' Unicode nul terminated string

  Public 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, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition 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         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
  Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

  Dim hKey As Long
  Dim SecAttr As SECURITY_ATTRIBUTES
  Dim strSubKey As String
  Dim lngNewExisting As Long
  Dim strKeyValue As String
  Dim hRetVal As Long

  Sub SetRegistry()
      strSubKey = "SOFTWARE\Microsoft\Office\8.0\Common\FileNew\LocalTemplates"
      strKeyValue = "C:\Program Files\Microsoft Office\Templates" & vbNullChar

      SecAttr.nLength = Len(SecAttr)
      SecAttr.lpSecurityDescriptor = 0
      SecAttr.bInheritHandle = True

      hRetVal = RegCreateKeyEx(HKEY_LOCAL_MACHINE, strSubKey, 0, "", 0, KEY_WRITE, SecAttr, hKey, lngNewExisting)
      If hRetVal = 0 Then
          hRetVal = RegSetValueEx(hKey, "(Default)", 0, REG_SZ, ByVal strKeyValue, Len(strKeyValue))
          hRetVal = RegCloseKey(hKey)
      End If
  End Sub


  > Hall all!
  >
  > How can I change a value in the registry, e.g. the name of the templatespath
  > of Word or of the sharedteplatespath?
  >
  > Thank!
  >
  > --
  > Dr. Michel Giraud
  > F.G. Theis KWW GmbH
  > Tel:( 02331) 693 276

  >
  >



Wed, 25 Jun 2003 07:15:26 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. searching values in the windows registry!!!

2. Reading a value from the Windows registry

3. How do I store values in the Windows Registry

4. Writing Registry Values in Windows NT (Permissions issue?)

5. Windows Messaging Subsystem Registry Value

6. Changing registry values

7. Change DWord Value in Registry with Vb5 or Vb6

8. change system values in NT registry

9. Change Registry values

10. How to change NT Registry values?

11. Changing Registry Values Directly

12. Changing Registry Binary Value

 

 
Powered by phpBB® Forum Software