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. - //first byte offset
-
const int start = 52;
-
//last byte offset
-
const int end = start + 15;
-
//decoded key length
-
const int length = 29;
-
//decoded key in byte form
-
const int decoded = 15;
-
-
public static DecodeKeyByteArray(byte id)
-
{
-
-
//char[] for holding the decoded product key
-
var decodedKey = new char[length];
-
-
//List<byte> to hold the key bytes
-
var keyHex = new List<byte>();
-
-
//list to hold possible alpha-numeric characters
-
//that may be in the product key
-
var charsInKey = new List<char>()
-
{
-
'B', 'C', 'D', 'F', 'G', 'H',
-
'J', 'K', 'M', 'P', 'Q', 'R',
-
'T', 'V', 'W', 'X', 'Y', '2',
-
'3', '4', '6', '7', '8', '9'
-
};
-
-
//add all bytes to our list
-
for (var i = start; i <= end; i++)
-
{
-
keyHex.Add(id[i]);
-
}
-
//now the decoding starts
-
for (var i = length - 1; i >= 0; i--)
-
-
switch ((i + 1) % 6)
-
{
-
//if the calculation is 0 (zero) then add the seperator
-
case 0:
-
decodedKey[i] = '-';
-
break;
-
default:
-
var idx = 0;
-
-
for (var j = decoded - 1; j >= 0; j--)
-
{
-
var @value = (idx << 8) | keyHex[j];
-
keyHex[j] = (byte)(@value / 24);
-
idx = @value % 24;
-
decodedKey[i] = charsInKey[idx];
-
}
-
break;
-
}
-
return new string(decodedKey);
-
}
-
-
-
private void btnGetSerialKey_Click(object sender, EventArgs e)
-
{
-
-
byte[] id = null;
-
var regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
-
-
if (regKey != null) id = regKey.GetValue("DigitalProductId") as byte[];
-
-
btnGetSerialKey.Text = DecodeKeyByteArray(id);
-
-
}
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.
1 2721
if the method - public static DecodeKeyByteArray(byte id)
returns a string then you must declare it as - public static string DecodeKeyByteArray(byte id)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
{
....
}
|
by: Michael C |
last post by:
eg
void DoIt()
{
int i = FromString("1");
double d = FromString("1.1");
}
int FromString(string SomeValue)
{
|
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...
|
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...
|
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,...
|
by: santhoshcz |
last post by:
Is it so the only reason we cannot call it explicitly or it has some other reason??
Thanks,
Santhosh.
|
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 ...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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: 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...
| |