zoukankan      html  css  js  c++  java
  • [转]C# 获取硬盘序列号 Volume Serial Number

    在做软件注册时,通常用硬盘号(建议用散列后的硬盘号)作为本地电脑特征码,加上用户名以及公司名等其他信息,通过一定的算法,得到软件序列号。这样做的好处的显而易见的。它可以防止一个序列号N多人用的现象。现在有些软件就是一个注册码,在网上公开,全世界人都在用。但是也有相应的缺陷。客户只能在一台电脑上用你写的软件。下面的方法通过Windows API获得硬盘号。
    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"); 
            }
     

     调用方法:例如C盘:GetVolOf("C");

    不过无论你的注册算法如何精妙,始终会被破解。因为你的算法始终在软件客户端,cracker总是有机会找到你的注册算法,做出注册机来。看看网上流传的五花八门的注册机就知道了。个人觉得如果做依赖Web的程序,最好还是把注册算法写在Web Service里面,这样cracker就没法从本地破解注册算法了,这样就大大增加了安全性。

  • 相关阅读:
    How To Scan QRCode For UWP (4)
    How To Crop Bitmap For UWP
    How To Scan QRCode For UWP (3)
    How To Scan QRCode For UWP (2)
    How To Scan QRCode For UWP (1)
    How to change windows applicatioin's position via Win32 API
    8 Ways to Become a Better Coder
    How to resize or create a thumbnail image from file stream on UWP
    C# winform压缩文件夹带进度条
    MS ACCESS MID函数
  • 原文地址:https://www.cnblogs.com/wangpei/p/1337510.html
Copyright © 2011-2022 走看看