Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:49:36+00:00 2026-06-17T15:49:36+00:00

I saved a byte array to registry using following code Byte[] value = new

  • 0

I saved a byte array to registry using following code

Byte[] value = new byte[16]{
    0x4a,0x03,0x00,0x00, 
    0x45,0x02,0x00,0x00, 
    0xb7,0x00,0x00,0x00, 
    0x9d,0x00,0x00,0x00
};

RegistryKey key = Registry.CurrentUser.CreateSubKey(KeyName);
key.SetValue(@"Software\Software\Key", value, RegistryValueKind.Binary);

Here is the key created using above code:

[HKEY_CURRENT_USER\Software\Software\Key]  
    "LOC"=hex:4a,03,00,00,45,02,00,00,b7,00,00,00,9d,00,00,00

Now I want to read the same data back to byte array format. Following code can read the same data but the output is of type object.

RegistryKey key = Registry.CurrentUser.OpenSubKey(KeyName);
object obj =  key.GetValue(@"Software\Software\Key", value);

Here casting to byte[] does not work. I know I can use serializer or streams to achieve this task. I would like to know if there is an easier way to read data back to byte[] type (A two liner code)?

Please note this question is in C++

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:49:37+00:00Added an answer on June 17, 2026 at 3:49 pm

    To write a byte array to registry use following code

    Byte[] value = new byte[]{
        0x4a,0x03,0x00,0x00, 
        0x45,0x02,0x00,0x00, 
        0xb7,0x00,0x00,0x00, 
        0x9d,0x00,0x00,0x00
    };
    
    RegistryKey key = Registry.CurrentUser.CreateSubKey(KeyName);
    key.SetValue(@"Software\AppName\Key", value, RegistryValueKind.Binary);
    

    To Retrieve the data back from registry into Byte[] format use following:

    RegistryKey key = Registry.CurrentUser.OpenSubKey(KeyName);
    byte[] Data =  (byte[]) key.GetValue(@"Software\AppName\Key", value);
    

    Note: CurrentUser is name of the root for your Key location and points to HKEY_CURRENT_USER

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code: Session[timestamp] has a byte array in it coming using LInq
Im using the ZipDotNet library for C#. I created a byte array with random
I'm trying to get a byte array of an image saved locally on the
I have the following code which takes an improperly saved Image from the database
I'm trying to use byte array (as BLOB saved in DB) to return the
Why doesn't the following code work (tested using Word documents and PDF files)? The
Is converting a file to a byte array the best way to save ANY
Seeing as you can convert any document to a byte array and save it
In .Net, you can generate byte code in memory, and presumably save the resulting
I saved some data in the database using mysql_real_escape_string() so the single quotes are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.