473,382 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help With Registry; CreateSubKey

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?

WHY:?
Setting Cookies to always block for a list of sites (3500+)
The key is
[HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\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?

**Attempted Code**
private string sSubKey =
@"Software\Microsoft\Windows\CurrentVersion\Intern et 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.


Nov 16 '05 #1
1 6623
Yogi_Bear_79 <IT*****@spamfree.com> wrote:
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
<snip>
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.


It seems to work fine for me - but note that in your code above, you're
setting the default value for Registry.CurrentUser, not your newly
created key. Here's my sample code:

using System;
using Microsoft.Win32;

class Test
{
static void Main()
{
using (RegistryKey key =
Registry.CurrentUser.CreateSubKey("Foo"))
{
key.SetValue (null, 5);
}
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: CMG | last post by:
I am writing a little code to associate an extention with my program. And as far as i can see, i need to do the following: Public Function associatefile(ByVal FILE_EXTENTION_TO_ASSOCIATE As...
3
by: JR | last post by:
Hi, How can I delete a registry value in vb.net Jan
2
by: cr | last post by:
Hello. I have a C# (Windows forms) project that uses OpenSubKey to write some values to a registry key. Here's the code: // Create the Installation registry key and values...
2
by: Ben | last post by:
I think I might have found a bug in Visual Studio. The following code should work and doesn't: My.Computer.Registry.LocalMachine.CreateSubKey("Software\Dravet")...
0
by: rbanerji | last post by:
I have a COM object built in C#. Its a an IE deskband. It implements the following method: public static void Register( Type t ) Which gets called when regasm is used and it makes teh...
5
by: Parv | last post by:
I am working in a domain environment. I am on a client machine and wants to edit registery of domain server. I am currently in a Domain user account and member of Domain administrators on the...
3
by: Aussie Rules | last post by:
Hi, I want to store some data in the registry, however I have not been able to do this, and think my logic maybe flawed. Firstly I try to open the registry and read in any existing values....
5
Sl1ver
by: Sl1ver | last post by:
I have this piece of code public bool Write(string KeyName, object Value) { try { // Setting string subKey1 =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.