
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, 20, 0, 0, 0, null, 0);
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--;
//}
}
}
}
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, 20, 0, 0, 0, null, 0);
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--;
//}
}
}
}
玩技术,要学会忍受寂寞--