黑夜的狼

沮丧吗,那就是一种无病呻吟!留恋它就是一种高度近视!目光应该放得更远一点! 别不想飞,只是要一步跨过太平洋!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; 

namespace RegisterMachine
{
    
public partial class Form1 : Form
    {
        [DllImport(
"KERNEL32.DLL")]
        
public static extern int GetDriveType(string lpRootPathName);

        [DllImport(
"KERNEL32.DLL", CharSet = CharSet.Auto)]
        
public static extern bool GetVolumeInformation(
  
string lpRootPathName,
  
string lpVolumeNameBuffer,
  
int nVolumeNameSize,
  
int lpVolumeSerialNumber,
  
int lpMaximumComponentLength,
  
int lpFileSystemFlags,
  
string lpFileSystemNameBuffer,
  
int nFileSystemNameSize
);

        
public Form1()
        {
            InitializeComponent();
        }

        
private void button1_Click(object sender, EventArgs e)
        {
            
int diskType = GetDriveType(null);
            
string vName = new string(' ',20);

            

            
bool b = GetVolumeInformation(null, vName, 20000null0);

            
byte[] buffer = System.Text.Encoding.Default.GetBytes(vName);
            
int invCount = 0;
            
string hexStr = string.Empty;
            
foreach (byte b1 in buffer)
            {
                
if (b1 != 0)
                {
                    hexStr 
= b1.ToString("X"+ hexStr;
                    invCount
++;
                }
                
else
                {
                    
break;
                }
            }



            
long resValue = unchecked(Convert.ToInt32(hexStr,16* (diskType * (diskType + 1/ 2));
            
long lStr = resValue ^ 0x797A7553;

            textBox1.Text 
= lStr.ToString();

            
//------------数组反转------------
            
//int count = buffer.Length;
            
//byte tempB;
            
//while (count > buffer.Length / 2)
            
//{
            
//    tempB = buffer[buffer.Length - count];
            
//    buffer[buffer.Length - count] = buffer[count - 1];
            
//    buffer[count - 1] = tempB;
            
//    count--;
            
//}

        }
    }
}

 

posted on 2010-03-21 15:22  anncesky  阅读(190)  评论(0)    收藏  举报