Change Type of (Default) Registry Value

  • Thread starter Thread starter Yogi_Bear_79
  • Start date Start date
Y

Yogi_Bear_79

I'm Creating new Keys in the registry, but when I do, they always have
a Vaule called (Default) type RG_SZ. I need them to be DWord
dword:00000005

Is there a way to automaticaly make the (Default) a Dword using the
CreateSubKey method?

If not, How can I use the SetValue Method t change the Default from
RG_SZ to DWord?
 
Setting Cookies to always block for a list of sites (3500+)
The key is
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\P3P\History\doubleclick.com]
@=dword:00000005

The only value in these keys is default, and it's a Dword. I can get it all
to work if I use VBS & a .txt file. As VBS allows me to create the subkey
(doubleclick.com) and it's value in one line of code.

Surely if VBS can do this C# can?
 
Indeed you're right, you can change the default value type. My
mistake.

Surely if VBS can do this C# can?

Yep

string key = @"Software\Microsoft\Windows\CurrentVersion" +
@"\Internet Settings\P3P\History\doubleclick.com";
using ( RegistryKey k = Registry.CurrentUser.OpenSubKey( key, true ) )
k.SetValue( null, 5 );



Mattias
 
Nice,
Didn't think of stringing them together like that...

Will test tommorow, thanks self teaching myself this
 
Mattias,

It still doesn't work..
private string sSubKey =
@"Software\Microsoft\Windows\CurrentVersion\Internet Settings\P3P\History\";

public void AddBlockCookies()

{

foreach(string x in strBlkCookiesLst)

{


RegistryKey Key = Registry.CurrentUser;

using (Key.CreateSubKey(sSubKey + x +
@"\"))Key.SetValue(null,Convert.ToInt32(00000005));

Key.Close;

}

}

Also tried
using (Key.OpenSubKey(sSubKey + x +
@"\"))Key.SetValue(null,Convert.ToInt32(00000005));

But since I have to create the key first to get this to work the default
value is already created, that's why I went to the first idea.
 
When you create the value the type is controlled by the data type of the
value parameter.

int ii=200;
string dd="Dog";

testSettings.SetValue("Animal", dd); //REG_SZ
testSettings.SetValue("ID", ii); //REG_DWORD

Bern
 
Back
Top