C # obtain the hard disk serial number volume serial number

Source: Internet
Author: User
During software registration, the hard disk number is usually used (the hash hard disk number is recommended) as the Local Computer pattern, and other information such as the user name and company name is used. Algorithm To obtain the software serial number. The benefits of doing so are obvious. It can prevent multiple users with a serial number of N. Currently, some software is a registration code published on the Internet and is used by people all over the world. But there are also corresponding defects. The customer can only use the software you write on one computer. The following method uses Windows API to obtain the hard disk number.

Using System. runtime. interopservices;
[Dllimport ( " Kernel32.dll " )]
Private   Static   Extern   Int Getvolumeinformation (
String Lprootpathname,
String Lpvolumenamebuffer,
Int Nvolumenamesize,
Ref   Int Lpvolumeserialnumber,
Int Lpmaximumcomponentlength,
Int Lpfilesystemflags,
String Lpfilesystemnamebuffer,
Int Nfilesystemnamesize
);

Private   String Getvolof ( String Drvid) ... {
Const   Int Max_filename_len =   256 ;
Int Retval =   0 ;
Int A = 0 ;
Int B = 0 ;
String Str1 =   Null ;
String Str2 =   Null ;
Int I = Getvolumeinformation (
Drvid +   @" : " ,
Str1,
Max_filename_len,
Ref Retval,
A,
B,
Str2,
Max_filename_len
);

Return Retval. tostring ( " X " );
}  

Call method: for example, drive C: getvolof ("C");

However, no matter how subtle your registration algorithm is, it will always be cracked. Because your algorithms are always on the software client, cracker always has the opportunity to find your registration algorithm and make a registration machine. Look at the various types of registration machines circulating on the Internet. I personally think thatProgramIt is best to write the Registration Algorithm in the Web service so that the cracker cannot crack the registration algorithm from the local machine, which greatly increases the security.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.