Writng the Binary Data into Registry

  • Thread starter Thread starter Saradhi
  • Start date Start date
Can any one put me a piece of code to write binary data into Registry?

I don't have a piece of C# code at hand as I'm not at home, but I believe
the technique is fairly simple:

1) Reference the Registry object in the Microsoft.Win32 namespace
2) Create the subkey (if it doesn't already exist) where the binary value
will reside
3) Convert the value to be stored into a byte array
4) Call the SetValue method of the Registry object

The following is a VB.NET example which you should be able to modify easily
for C#:

Dim rk As Microsoft.Win32.RegistryKey
rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\Test")
Dim b() As Byte = {1, 2, 3, 4, 5, 6}
rk.SetValue("A Value", b)

HTH.

Mark
 
This make sense. But I would like to put an image data into the registry.
For example, I have a Add-In and I have it's AboutBoxIcon and I am trying to change the Icon depending on some logic.
Wt could be the best way to do it?

Can any one put me a piece of code to write binary data into Registry?

I don't have a piece of C# code at hand as I'm not at home, but I believe
the technique is fairly simple:

1) Reference the Registry object in the Microsoft.Win32 namespace
2) Create the subkey (if it doesn't already exist) where the binary value
will reside
3) Convert the value to be stored into a byte array
4) Call the SetValue method of the Registry object

The following is a VB.NET example which you should be able to modify easily
for C#:

Dim rk As Microsoft.Win32.RegistryKey
rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\Test")
Dim b() As Byte = {1, 2, 3, 4, 5, 6}
rk.SetValue("A Value", b)

HTH.

Mark
 
Saradhi,

In this case, I would generate separate named values for each icon and
then use the logic to determine which key to access.

Also, have you considered using resources for storing this information?
It's a little more suited, IMO, for this kind of thing.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

This make sense. But I would like to put an image data into the registry.
For example, I have a Add-In and I have it's AboutBoxIcon and I am trying to
change the Icon depending on some logic.
Wt could be the best way to do it?

Can any one put me a piece of code to write binary data into Registry?

I don't have a piece of C# code at hand as I'm not at home, but I believe
the technique is fairly simple:

1) Reference the Registry object in the Microsoft.Win32 namespace
2) Create the subkey (if it doesn't already exist) where the binary value
will reside
3) Convert the value to be stored into a byte array
4) Call the SetValue method of the Registry object

The following is a VB.NET example which you should be able to modify easily
for C#:

Dim rk As Microsoft.Win32.RegistryKey
rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\Test")
Dim b() As Byte = {1, 2, 3, 4, 5, 6}
rk.SetValue("A Value", b)

HTH.

Mark
 
I wouldn't use the Registry for this, at least, not to store the actual
icon. Instead, I would keep the various icons in a subfolder somewhere on
the machine in question - if your code can read the Registry, it can also
read the file system - and then determine which one to use as required.

The Registry is designed for (and best suited to) storing lots of little
bits of information, not as a substitute for the file system




This make sense. But I would like to put an image data into the registry.
For example, I have a Add-In and I have it's AboutBoxIcon and I am trying to
change the Icon depending on some logic.
Wt could be the best way to do it?

Can any one put me a piece of code to write binary data into Registry?

I don't have a piece of C# code at hand as I'm not at home, but I believe
the technique is fairly simple:

1) Reference the Registry object in the Microsoft.Win32 namespace
2) Create the subkey (if it doesn't already exist) where the binary value
will reside
3) Convert the value to be stored into a byte array
4) Call the SetValue method of the Registry object

The following is a VB.NET example which you should be able to modify easily
for C#:

Dim rk As Microsoft.Win32.RegistryKey
rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\Test")
Dim b() As Byte = {1, 2, 3, 4, 5, 6}
rk.SetValue("A Value", b)

HTH.

Mark
 
This make sense. But I would like to put an image data into the registry.
For example, I have a Add-In and I have it's AboutBoxIcon and I am trying to change the Icon depending on some logic.
Wt could be the best way to do it?

This really constitutes abuse of the registry. Part of the reason Windows
is so flakey is because of morons using it as a database.
 
The .NET method of storing such data would be by using resources. Consider going thru those lines.

Regards,
fbhcah
 
Also, have you considered using resources for storing this information?
It's a little more suited, IMO, for this kind of thing.

Can you suggest an on-line introduction to this?
 
Its not abuse.
You misunderstood my requirements.

I would like to load my Add-In only in certain situations and I am opening the Visual Studio.NET IDE from my application and whenever the user opens the VS IDE, my add-in got to be loaded.

The only thing you need to do is to add information to the REgistry in the sessions AddIns and VS.NET IDE automatically opens your Add-In as it takes the info from the registry and hence our add-in will be loaded automatically.

We have the following info to be loaded :
AboutBoxDetails,AboutBoxIcon,CommandPreload,FriendlyName,Description, LoadBehavior , CommandLineSafe, CommandPreload

No harm if you wont specify the icon for your Add-In AboutBox, but its always recomendable if you can choose one if MS gave you the permission.
I never mentioned anywhere that I am using Registry as a substituion for File System.


This make sense. But I would like to put an image data into the registry.
For example, I have a Add-In and I have it's AboutBoxIcon and I am trying to change the Icon depending on some logic.
Wt could be the best way to do it?

This really constitutes abuse of the registry. Part of the reason Windows
is so flakey is because of morons using it as a database.
 
You misunderstood my requirements.
Try to understand the requirements before replying.

I would like to load my Add-In only in certain situations and I am opening the Visual Studio.NET IDE from my application and whenever the user opens the VS IDE, my add-in got to be loaded.

The only thing you need to do is to add information to the REgistry in the sessions AddIns and VS.NET IDE automatically opens your Add-In as it takes the info from the registry and hence our add-in will be loaded automatically.

We have the following info to be loaded :
AboutBoxDetails,AboutBoxIcon,CommandPreload,FriendlyName,Description, LoadBehavior , CommandLineSafe, CommandPreload

No harm if you wont specify the icon for your Add-In AboutBox, but its always recomendable if you can choose one if MS gave you the permission to give.

I never mentioned anywhere that I am using Registry as a substitution for File System.
I wouldn't use the Registry for this, at least, not to store the actual
icon. Instead, I would keep the various icons in a subfolder somewhere on
the machine in question - if your code can read the Registry, it can also
read the file system - and then determine which one to use as required.

The Registry is designed for (and best suited to) storing lots of little
bits of information, not as a substitute for the file system




This make sense. But I would like to put an image data into the registry.
For example, I have a Add-In and I have it's AboutBoxIcon and I am trying to
change the Icon depending on some logic.
Wt could be the best way to do it?

Can any one put me a piece of code to write binary data into Registry?

I don't have a piece of C# code at hand as I'm not at home, but I believe
the technique is fairly simple:

1) Reference the Registry object in the Microsoft.Win32 namespace
2) Create the subkey (if it doesn't already exist) where the binary value
will reside
3) Convert the value to be stored into a byte array
4) Call the SetValue method of the Registry object

The following is a VB.NET example which you should be able to modify easily
for C#:

Dim rk As Microsoft.Win32.RegistryKey
rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\Test")
Dim b() As Byte = {1, 2, 3, 4, 5, 6}
rk.SetValue("A Value", b)

HTH.

Mark
 
Hi

If u had got any idea as how LoadBehaviour for add-in gets changed from 3 to 2 , pls do intimate me

Thx from advance

I require urgently

Th
Ajay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top