将硬盘驱动器串行字符串写入二进制文件
|
我有一个简单的函数,可以从C:\\驱动器获取硬盘驱动器序列号,并将其放入字符串中:
ManagementObject disk = new ManagementObject(\"win32_logicaldisk.deviceid=\\\"C:\\\"\");
disk.Get();
string hdStr = Convert.ToString(disk[\"VolumeSerialNumber\"]);
然后,我尝试将上面的字符串转换为ASCII,然后将其写出为二进制文件,当转换此字符串并使用Streamwriter保存文件并以十六进制打开文件时,我遇到的问题是编辑器中,我看到了更多本来想写的字节,例如\“ 16342D1F4A61BC \”
将显示为:08 16 34 2d 1f 4a 61 c2 bc
它以某种方式在其中添加了08和c2 ...
更完整的版本如下:
string constructor2 = \"16342D1F4A61BC\";
string StrValue = \"\";
while (constructor2.Length > 0)
{
StrValue += System.Convert.ToChar(System.Convert.ToUInt32(constructor2.Substring(0, 2), 16)).ToString();
// Remove from the hex object the converted value
constructor2 = constructor2.Substring(2, constructor2.Length - 2);
}
FileStream writeStream;
try
{
writeStream = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + \"\\\\license.mgr\", FileMode.Create);
BinaryWriter writeBinay = new BinaryWriter(writeStream);
writeBinay.Write(StrValue);
writeBinay.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
谁能帮助我了解如何添加这些内容?
没有找到相关结果
已邀请:
3 个回复
粱委教
使用以下帮助程序:
掸牛浓疗
翰冒绢县