473,382 Members | 1,386 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.

method must have a return type

134 100+
Hello all,

I am trying to get a program which can retrieve the serial key of Windows from the Registry. I've found the source code on this website, but I can't seem to get it working.
This is the source code as I have it right now.
Expand|Select|Wrap|Line Numbers
  1. //first byte offset
  2.         const int start = 52;
  3.         //last byte offset
  4.         const int end = start + 15;
  5.         //decoded key length
  6.         const int length = 29;
  7.         //decoded key in byte form
  8.         const int decoded = 15;
  9.  
  10.         public static DecodeKeyByteArray(byte id)
  11.         {
  12.  
  13.             //char[] for holding the decoded product key
  14.             var decodedKey = new char[length];
  15.  
  16.             //List<byte> to hold the key bytes
  17.             var keyHex = new List<byte>();
  18.  
  19.             //list to hold possible alpha-numeric characters
  20.             //that may be in the product key
  21.             var charsInKey = new List<char>()
  22.                     {
  23.                         'B', 'C', 'D', 'F', 'G', 'H', 
  24.                         'J', 'K', 'M', 'P', 'Q', 'R', 
  25.                         'T', 'V', 'W', 'X', 'Y', '2', 
  26.                         '3', '4', '6', '7', '8', '9'
  27.                     };
  28.  
  29.             //add all bytes to our list
  30.             for (var i = start; i <= end; i++)
  31.             {
  32.                 keyHex.Add(id[i]);
  33.             }
  34.             //now the decoding starts
  35.             for (var i = length - 1; i >= 0; i--)
  36.  
  37.                 switch ((i + 1) % 6)
  38.                 {
  39.                     //if the calculation is 0 (zero) then add the seperator
  40.                     case 0:
  41.                         decodedKey[i] = '-';
  42.                         break;
  43.                     default:
  44.                         var idx = 0;
  45.  
  46.                         for (var j = decoded - 1; j >= 0; j--)
  47.                         {
  48.                             var @value = (idx << 8) | keyHex[j];
  49.                             keyHex[j] = (byte)(@value / 24);
  50.                             idx = @value % 24;
  51.                             decodedKey[i] = charsInKey[idx];
  52.                         }
  53.                         break;
  54.                 }
  55.             return new string(decodedKey);
  56.         }
  57.  
  58.  
  59.         private void btnGetSerialKey_Click(object sender, EventArgs e)
  60.         {
  61.  
  62.             byte[] id = null;
  63.             var regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
  64.  
  65.             if (regKey != null) id = regKey.GetValue("DigitalProductId") as byte[];
  66.  
  67.             btnGetSerialKey.Text = DecodeKeyByteArray(id);
  68.  
  69.         }
Visual Studio keep saying that I must have a return method, but since I have a return method. I just don't know why it is going wrong.

Thanks in advance for the help.
Mar 23 '13 #1
1 2721
r035198x
13,262 8TB
if the method
Expand|Select|Wrap|Line Numbers
  1.  public static DecodeKeyByteArray(byte id)
returns a string then you must declare it as

Expand|Select|Wrap|Line Numbers
  1. public static string DecodeKeyByteArray(byte id)
Mar 23 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nuno Barros | last post by:
Hello, I am writting a c++ code to crete a kind of a table in memory. Each table has an container of columns, which can be of any type. To do this i created a virtual class Column which has...
3
by: Jarmo Muukka | last post by:
Hello, I have an interface which has a method which returns an interface. I would like to return a real type in implemented class. interface IFoo { .... }
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
5
by: Brad Wood | last post by:
It doesn't look like something like this is possible in 2.0: public <T> doStuff(); Am I correct, and if so, there's probably a good reason that I can't think of why not...
2
by: ABC | last post by:
Can I create an Interface which have a method have variate type parameters? I want create an Interface named IDataEditable which have two methods: LoadRecord and SaveRecord. As the LoadRecord...
8
by: WakeBdr | last post by:
I'm writing a class that will query a database for some data and return the result to the caller. I need to be able to return the result of the query in several different ways: list, xml,...
2
by: santhoshcz | last post by:
Is it so the only reason we cannot call it explicitly or it has some other reason?? Thanks, Santhosh.
3
by: BombDrop | last post by:
Can any one help I have a method that will return a List to be bound as a datasource to a combobox see code for population below. I get the following error when i try to compile Error 29 ...
1
by: eshortt84 | last post by:
hey, i'm new to java and i keep getting the return type required error on this line; public dvds(int productNum, String name, int units, double price, String rating) { The code for the whole...
2
by: Ajit Bhoravkar | last post by:
As a method returns a int value we have return type as a int and if method returns nothing we use return type as a void. If the method is not returning anything then why should we use void. I know...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.