取CPU序列号,获取网卡,取硬盘系列号,获取目录下的文件,强制删除目录
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- TFileItem = class(TCollectionItem)
- public
- FileName: WideString;
- FileSize: Int64;
- IsDirectory: Boolean;
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- //------ 取CPU序列号 uses WinSock
- function GetCPUID: string;
- procedure SetCPU(Handle: THandle; CPUNO: Integer);
- var
- ProcessAffinity: Cardinal;
- _SystemAffinity: Cardinal;
- begin
- GetProcessAffinityMask(handle, ProcessAffinity, _SystemAffinity);
- ProcessAffinity := CPUNO;
- SetProcessAffinityMask(handle, ProcessAffinity);
- end;
- const
- CPUINFO = '%.8x-%.8x-%.8x-%.8x';
- var
- iEax: Integer;
- iEbx: Integer;
- iEcx: Integer;
- iEdx: Integer;
- begin
- SetCPU(GetCurrentProcess, 1);
- asm
- push ebx
- push ecx
- push edx
- mov eax, 1
- DW $A20F//cpuid
- mov iEax, eax
- mov iEbx, ebx
- mov iEcx, ecx
- mov iEdx, edx
- pop edx
- pop ecx
- pop ebx
- end;
- Result := Format(CPUINFO, [iEax, iEbx, iEcx, iEdx]);
- end;
- //获取网卡
- function MacAddress: string;
- var
- Lib: Cardinal;
- Func : function(GUID: PGUID): Longint; stdcall;
- GUID1, GUID2: TGUID;
- begin
- Result := '';
- Lib := LoadLibrary('rpcrt4.dll');
- if Lib <> 0 then
- begin
- if Win32Platform <>VER_PLATFORM_WIN32_NT then
- @Func := GetProcAddress(Lib, 'UuidCreate')
- else @Func := GetProcAddress(Lib, 'UuidCreateSequential');
- if Assigned(Func) then
- begin
- if (Func(@GUID1) = 0) and
- (Func(@GUID2) = 0) and
- (GUID1.D4[2] = GUID2.D4[2]) and
- (GUID1.D4[3] = GUID2.D4[3]) and
- (GUID1.D4[4] = GUID2.D4[4]) and
- (GUID1.D4[5] = GUID2.D4[5]) and
- (GUID1.D4[6] = GUID2.D4[6]) and
- (GUID1.D4[7] = GUID2.D4[7]) then
- begin
- Result :=
- IntToHex(GUID1.D4[2], 2) + '-' +
- IntToHex(GUID1.D4[3], 2) + '-' +
- IntToHex(GUID1.D4[4], 2) + '-' +
- IntToHex(GUID1.D4[5], 2) + '-' +
- IntToHex(GUID1.D4[6], 2) + '-' +
- IntToHex(GUID1.D4[7], 2);
- end;
- end;
- FreeLibrary(Lib);
- end;
- end;
- //取硬盘系列号:
- function GetIdeSerialNumber: Pansichar; //获取硬盘的出厂系列号;
- const IDENTIFY_BUFFER_SIZE = 512;
- type
- TIDERegs = packed record
- bFeaturesReg: BYTE;
- bSectorCountReg: BYTE;
- bSectorNumberReg: BYTE;
- bCylLowReg: BYTE;
- bCylHighReg: BYTE;
- bDriveHeadReg: BYTE;
- bCommandReg: BYTE;
- bReserved: BYTE;
- end;
- TSendCmdInParams = packed record
- cBufferSize: DWORD;
- irDriveRegs: TIDERegs;
- bDriveNumber: BYTE;
- bReserved: array[0..2] of Byte;
- dwReserved: array[0..3] of DWORD;
- bBuffer: array[0..0] of Byte;
- end;
- TIdSector = packed record
- wGenConfig: Word;
- wNumCyls: Word;
- wReserved: Word;
- wNumHeads: Word;
- wBytesPerTrack: Word;
- wBytesPerSector: Word;
- wSectorsPerTrack: Word;
- wVendorUnique: array[0..2] of Word;
- sSerialNumber: array[0..19] of CHAR;
- wBufferType: Word;
- wBufferSize: Word;
- wECCSize: Word;
- sFirmwareRev: array[0..7] of Char;
- sModelNumber: array[0..39] of Char;
- wMoreVendorUnique: Word;
- wDoubleWordIO: Word;
- wCapabilities: Word;
- wReserved1: Word;
- wPIOTiming: Word;
- wDMATiming: Word;
- wBS: Word;
- wNumCurrentCyls: Word;
- wNumCurrentHeads: Word;
- wNumCurrentSectorsPerTrack: Word;
- ulCurrentSectorCapacity: DWORD;
- wMultSectorStuff: Word;
- ulTotalAddressableSectors: DWORD;
- wSingleWordDMA: Word;
- wMultiWordDMA: Word;
- bReserved: array[0..127] of BYTE;
- end;
- PIdSector = ^TIdSector;
- TDriverStatus = packed record
- bDriverError: Byte;
- bIDEStatus: Byte;
- bReserved: array[0..1] of Byte;
- dwReserved: array[0..1] of DWORD;
- end;
- TSendCmdOutParams = packed record
- cBufferSize: DWORD;
- DriverStatus: TDriverStatus;
- bBuffer: array[0..0] of BYTE;
- end;
- var
- hDevice: Thandle;
- cbBytesReturned: DWORD;
- SCIP: TSendCmdInParams;
- aIdOutCmd: array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE-1)-1] of Byte;
- IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;
- procedure ChangeByteOrder(var Data; Size: Integer);//函数中的过程
- var
- ptr: Pchar;
- i: Integer;
- c: Char;
- begin
- ptr := @Data;
- for I := 0 to (Size shr 1) - 1 do begin
- c := ptr^;
- ptr^ := (ptr + 1)^;
- (ptr + 1)^ := c;
- Inc(ptr, 2);
- end;
- end;
- begin //函数主体
- Result := '';
- if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then
- begin // Windows NT, Windows 2000
- hDevice := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
- FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
- end
- else // Version Windows 95 OSR2, Windows 98
- hDevice := CreateFile('\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);
- if hDevice = INVALID_HANDLE_VALUE then Exit;
- try
- FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);
- FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);
- cbBytesReturned := 0;
- with SCIP do
- begin
- cBufferSize := IDENTIFY_BUFFER_SIZE;
- with irDriveRegs do
- begin
- bSectorCountReg := 1;
- bSectorNumberReg := 1;
- bDriveHeadReg := $A0;
- bCommandReg := $EC;
- end;
- end;
- if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1,@aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then Exit;
- finally
- CloseHandle(hDevice);
- end;
- with PIdSector(@IdOutCmd.bBuffer)^ do
- begin
- ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));
- (Pchar(@sSerialNumber) + SizeOf(sSerialNumber))^:= #0;
- Result := PAnsichar(@sSerialNumber);
- end;
- end;
- //获取目录下的文件
- procedure FindAllFiles(APath: WideString; AFiles: TCollection;
- var AFileSize: Int64);
- var
- strSearchPath: WideString;
- strSafePath: WideString;
- FindData: WIN32_FIND_DATAW;
- hFind: THandle;
- objItem: TFileItem;
- begin
- strSafePath := Trim(APath);
- if strSafePath[Length(strSafePath)] <> '\' then strSafePath := strSafePath + '\';
- strSearchPath := strSafePath + '*.*';
- hFind := FindFirstFileW(PWideChar(strSearchPath), FindData);
- if (INVALID_HANDLE_VALUE = hFind) then Exit;
- while True do
- begin
- if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then
- begin
- if(FindData.cFileName[0] <> '.') then
- begin
- objItem := TFileItem(AFiles.Add());
- objItem.FileName := strSafePath + FindData.cFileName;
- objItem.FileSize := 0;
- objItem.IsDirectory := True;
- FindAllFiles(strSafePath + FindData.cFileName, AFiles, AFileSize);
- end;
- end
- else
- begin
- objItem := TFileItem(AFiles.Add());
- objItem.FileName := strSafePath + FindData.cFileName;
- objItem.FileSize := FindData.nFileSizeLow or FindData.nFileSizeHigh shl SizeOf(FindData.nFileSizeHigh);
- objItem.IsDirectory := False;
- AFileSize := AFileSize + objItem.FileSize;
- end;
- if (not FindNextFileW(hFind, FindData)) then Break;
- end;
- Windows.FindClose(hFind);
- end;
- //强制删除目录
- function ForceToRemoveDir(ADir: string): Boolean;
- var
- pDir: PChar;
- SR: TSearchRec;
- FR: Integer;
- begin
- Result := False;
- pDir := PChar(ADir);
- if not DirectoryExists(pDir) then Exit;
- try
- if Copy(pDir, Length(pDir), 1) <> '\' then
- pDir := PChar(pDir + '\');
- FR := FindFirst(pDir + '*.*', FaAnyfile, SR);
- while FR = 0 do
- begin
- if ((SR.Attr and FaDirectory) = FaDirectory) and
- (SR.Name <> '.') and (SR.Name <> '..') then
- begin
- if not ForceToRemoveDir(StrPas(pDir) + SR.Name) then Break;
- end;
- if ((SR.Attr and FaDirectory <> FaDirectory) and
- (SR.Attr and FaVolumeID <> FaVolumeID)) then
- begin
- SysUtils.FileSetAttr(pDir + SR.Name,
- SysUtils.FileGetAttr(pDir + SR.Name) and (not
- SysUtils.faReadOnly)); //取消文件的只读属性
- if not DeleteFile(PChar(pDir + SR.Name)) then
- Break;
- end;
- FR := FindNext(SR);
- end;
- SysUtils.FindClose(SR);
- RemoveDirectory(pDir);
- Result := True;
- except
- end;
- end;
- //获取windows系统版本
- function GetWindowsVersion: string;
- var
- AWin32Version: Extended;
- os: string;
- begin
- os := 'Windows ';
- AWin32Version := StrtoFloat(format('%d.%d' ,[Win32MajorVersion, Win32MinorVersion]));
- if Win32Platform = VER_PLATFORM_WIN32s then
- Result := os + '32'
- else if Win32Platform=VER_PLATFORM_WIN32_WINDOWS then
- begin
- if AWin32Version=4.0 then
- Result := os + '95'
- else if AWin32Version=4.1 then
- Result := os + '98'
- else if AWin32Version=4.9 then
- Result := os + 'Me'
- else
- Result := os + '9x'
- end
- else if Win32Platform = VER_PLATFORM_WIN32_NT then
- begin
- if AWin32Version=3.51 then
- Result := os + 'NT 3.51'
- else if AWin32Version=4.0 then
- Result := os + 'NT 4.0'
- else if AWin32Version=5.0 then
- Result := os + '2000'
- else if AWin32Version=5.1 then
- Result := os + 'XP'
- else if AWin32Version=5.2 then
- Result := os + '2003'
- else if AWin32Version=6.0 then
- Result := os + 'Vista'
- else if AWin32Version=6.1 then
- Result := os + '7'
- else
- Result := os ;
- end
- else
- Result := os + '??';
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var
- i:integer;
- begin
- showmessage(MacAddress());
- showmessage(GetCPUID());
- showmessage(GetIdeSerialNumber());
- showmessage(GetWindowsVersion());
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- var
- aFiles: TCollection;
- aFileSize: Int64;
- begin
- //FindAllFiles('C:\\apache-tomcat-6.0.32',aFiles,aFileSize);
- //showmessage(inttostr(aFileSize));
- ForceToRemoveDir('C:\apache-tomcat-6.0.32');
- showmessage('删除目录成功!');
- end;
- end.
http://blog.csdn.net/earbao/article/details/19629579
取CPU序列号,获取网卡,取硬盘系列号,获取目录下的文件,强制删除目录的更多相关文章
- PHP 获取指定目录下所有文件(包含子目录)
PHP 获取指定目录下所有文件(包含子目录) //glob — 寻找与模式匹配的文件路径 $filter_dir = array('CVS', 'templates_c', 'log', 'img', ...
- PHP 批量获取指定目录下的文件列表(递归,穿透所有子目录)
//调用 $dir = '/Users/xxx/www'; $exceptFolders = array('view','test'); $exceptFiles = array('BaseContr ...
- 阿里云OSS 获取目录下所有文件
public class AliyunHandle { public static string accessKeyId = "a1uI5xxxxxxxxxrP4H"; publi ...
- Python开发【笔记】:获取目录下所有文件
获取文件 import os def sub_dirs(rdir): li = os.listdir(rdir) return li def main(rdir): content = sub_dir ...
- [转]C# 获取指定目录下所有文件信息、移动目录、拷贝目录
原文:http://blog.csdn.net/vchao13/article/details/6200255 1.获取指定目录下所有文件信息 /// <summary> /// 返回指定 ...
- 如何用DOS命令,获取一个目录下的文件数目
发信人: GOOGOODALLS (我爱Figo), 信区: DOS 标 题: 如何用DOS命令,获取一个目录下的文件数目? 发信站: 水木社区 (Fri Mar 9 08:40:01 2007) ...
- 【转载】linux如何将新硬盘挂载到home目录下
举例说明: 新增磁盘的设备文件名为 /dev/vdb 大小为100GB. #fdisk -l 查看新增的的磁盘 1.对新增磁盘进行分区 #fdisk /dev/vdb 按提示操作 p打印 n新增 d ...
- Golang获取目录下的文件及目录信息
一.获取当前目录下的文件或目录信息(不包含多级子目录) func main() { pwd,_ := os.Getwd() //获取当前目录 //获取文件或目录相关信息 fileInfoList ...
- C# 获取CPU序列号、网卡MAC地址、硬盘序列号封装类,用于软件绑定电脑
using System.Management; namespace GLaLa { /// <summary> /// hardware_mac 的摘要说明. /// </summ ...
随机推荐
- C#_事件
C#_事件 概述 今天用来演示事件的例子是模拟实现一个文件下载类,在这个类中我将定义一个DownLoad事件,这个事件用来在文件下载的过程中,向订阅这个事件的用户发出消息,而这个消息将用DownLoa ...
- C#利用Lambda和Expression实现数据的动态绑定
在程序开发过程中,有时为了让数据能够实时更新,我们会采用数据绑定来实现. 一般我们数据绑定时我们是这样写的 public class Helper : INotifyPropertyChanged { ...
- POJ 2250(最长公共子序列 变形)
Description In a few months the European Currency Union will become a reality. However, to join the ...
- Eclipse用法和技巧八:自动添加try/catch块1
站在编译器的角度来看,java中的异常可以分为两种,已检查异常和未检查异常.对于已检查异常比如IO操作,编译器会要求设置try/catch语句块,在eclipse中也只要使用帮助快捷键ctrl+1,就 ...
- javascript 中 undefined 和 null 区别
1.相同点 如果我们直接用 undefined == null 比较他们是相等的返回的将是 true. 2.区别 当我们用undefined === null 比较的时候最后返回的将是 false. ...
- Windows下与Linux下编写socket程序的区别 《转载》
原文网址:http://blog.chinaunix.net/uid-2270658-id-308160.html [[Windows]] [Windows: 头文件的区别] #include< ...
- 解决Ajax.BeginForm还是刷新页面的问题
在.net mvc中用Ajax.BeginForm来实现异步提交,在Ajax.BeginForm里面还是可以用submit按钮,一般来说 submit按钮是提交整个页面的数据.但是在Ajax.Begi ...
- asp.net ajax 检测用户名是否可用代码
原文 asp.net ajax 检测用户名是否可用代码 .net ajax 检测用户名是否可用代码 <script type="text/网页特效" src="c ...
- Windows 8 动手实验系列教程 实验6:设置和首选项
动手实验 实验6:设置和首选项 2012年9月 简介 实验3介绍了合约并演示了应用程序如何轻松地与共享和搜索合约实现集成.合约同样包含设置超级按钮,它对活动的Windows应用商店应用的设置进行修改. ...
- Spark大型项目实战:电商用户行为分析大数据平台
本项目主要讲解了一套应用于互联网电商企业中,使用Java.Spark等技术开发的大数据统计分析平台,对电商网站的各种用户行为(访问行为.页面跳转行为.购物行为.广告点击行为等)进行复杂的分析.用统计分 ...