取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 ...
随机推荐
- 怎样用HTML5 Canvas制作一个简单的游戏
原文连接: How To Make A Simple HTML5 Canvas Game 自从我制作了一些HTML5游戏(例如Crypt Run)后,我收到了很多建议,要求我写一篇关于怎样利用HTML ...
- CF 319C(Kalila and Dimna in the Logging Industry-斜率DP,注意叉积LL溢出)
C. Kalila and Dimna in the Logging Industry time limit per test 2 seconds memory limit per test 256 ...
- C#调用存储过程实现分页(个人代码笔记)
分页的存储过程: drop proc LoadPageMain create Proc LoadPageMain @pageIndex )) Fid ) ].Rows ) ...
- Swing Dance!摇摆舞!小组
Swing Dance!摇摆舞!小组 Swing Dance!摇摆舞
- EF连接MySQL数据Web.Config配置
EF连接MySQL数据Web.Config配置 <?xml version="1.0" encoding="utf-8"?> <configu ...
- tomcat 后台启动设置
如果你环境变量配置对了且保证tomcat的bin目录下有如下三个文件,则你只需在cmd中运行 service install tomcat即可将tomcat添加的服务项中,然后在设置开机自动启动,则以 ...
- shell 调用mysql 存储过程判断真假
mysql> create table TBL_STUDENT(id int,name char(10),CLASSNO int,BIRTH datetime); Query OK, 0 row ...
- Zookeeper从入门到精通(开发详解,案例实战,Web界面监控)
ZooKeeper是Hadoop的开源子项目(Google Chubby的开源实现),它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护.命名服务.分布式同步.组服务等. Zookee ...
- Linux 下获取LAN中指定IP的网卡的MAC(物理地址)
// all.h// 2005/06/20,a.m. wenxy #ifndef _ALL_H#define _ALL_H #include <memory.h>#include < ...
- Codility上的问题 (17) PI 2012
这个题比较简单,给定一个整数数组,对每个元素,求出和它最近比它大的数的距离(下标绝对值),如果没有比它大的数,认为距离是0. 数组元素个数 N [0..50000],数组元素范围[-10^9, +10 ...