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

Editing the windows Registry

Status
Not open for further replies.

BobBob10

Programmer
Apr 24, 2005
57
GB
Hi I need to add these values:

value name: BrowserFlags
Data type: REG_DWORD
Value: 8

to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.Sheet.8

I can do this manually be going to start/run, typing regedt.
Locating the above by going through the directories, then clicking Edit-new-Reg_dword and typing the name and value. however, i need to do this programatically.

Can anyone help?
 
You can do it easily using SHSetValue light-weight API function.
___
[tt]
Private Declare Function SHSetValue Lib "SHLWAPI" Alias "SHSetValueA" (ByVal hKey As Long, ByVal pszSubKey As String, ByVal pszValue As String, ByVal dwType As Long, pvData As Any, ByVal cbData As Long) As Long
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_DWORD = 4
...
SHSetValue HKEY_LOCAL_MACHINE, "Software\Classes\Excel.Sheet.8", "BrowserFlags", REG_DWORD, 8&, 4[/tt]
___

You can also call the SHSetValue function with these parameters.
[tt]
SHSetValue HKEY_CLASSES_ROOT, "Excel.Sheet.8", "BrowserFlags", REG_DWORD, 8&, 4
[/tt]
This realizes the fact that HKCR is a direct mapping of HKLM\Software\Classes key.
 
Brillant, thats great stuff.

However, how would I check to see whether the subkey already exist, because if it does than I do not want to create another (it will only error).

Also, i need to roll this out to my department. Is the best way of doing this, by making the sub main into an .exe and emailing this to them?
 
If you want to write a program just to update this registry value, you better write and distribute a registry file (.reg file), instead of writing an application (.exe file).

The following registration entries do exactly the same as the above code. But you don't need to compile an executable. You save the entries in a plain text file with .reg extension.
[tt]
REGEDIT4
[HKEY_CLASSES_ROOT\Excel.Sheet.8]
"BrowserFlags"=dword:00000008
[/tt]
See also the followig MSKB article.

How to add, modify, or delete registry subkeys and values by using a registration entries (.reg) file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top