取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 ...
随机推荐
- Oracle成长点点滴滴(3)— 权限管理
上篇我们解说了创建用户以及主要的授权问题.以下我们来解说权限包含对象权限和系统权限. 事实上上节课我们解说就是系统的权限.系统权限就是一些创建表了,表空间等等的系统的权限. 1. 系统权限 ...
- pssh,pscp,pslurp使用实践
因为常常须要到几十台机器上运行同样的命令,而眼下机器上还没有部署Saltstack或Puppet等集群化管理工具. 因为每台server上都使用同样的公钥,故之前都是写一些脚本:把IP 放到一个文件里 ...
- Web用户控件
用户控件是个什么东西?自定义的反复重用的控件集合 注意:创建好用户控件后,必须添加到其他web页中才能显示出来,不能直接作为一个网页来显示,因此也就不能设置用户控件为“起始页”. 用户控件与ASP.N ...
- ImageMagick wrapper for php
https://code.google.com/archive/p/phmagick/
- 《UNIX环境高级编程》笔记--read函数,write函数,lseek函数
1.read函数 调用read函数从文件去读数据,函数定义如下: #include <unistd.h> ssize_t read(int filedes, void* buff, siz ...
- Ubuntu 14.04LTS Gnome GUI初体验及163更新源配制
Ubuntu 14.04 LTS于前天(2014.4.17)公布, 我今天将我的系统升级到最新, 体验了下最新的UI系统. 我选择了Ubuntu Gnome 的GUI界面.我曾经的系统是12.04lt ...
- 管理支撑办公系统技术架构选型对照讨论(J2EE与SOA对照)
续:管理支撑办公系统技术架构选型及相关技术应用范围.方法分析 M域办公系统改造.整合涉及到OA.业务流程.部室信息站点.部室专业管理等系统和信息共享等新需求,从信息化视角来看,内容多并且杂,这里核心业 ...
- asp.net微软认证全新考试题库及答案1
1.你创建了一个ASP.net应用程序,该程序将运行在TK公司的WEB站点上.你的应用程序包括100个WEB页面.你想配置你的应用程序,当HTTP代码发生错误时,可显示自定义的错误信息给用户.同时你想 ...
- MSSQL - SQL Server2008附加数据库失败 错误号:5120
附加数据库时,显示错误,错误信息为 一种解决方法为,设置mdf文件所在文件夹的权限(有些资料说只设置mdf文件的权限就好,但我试了不管用),在文件夹上右击——属性——安全,如图所示: 选择组或用户名中 ...
- ASP.NET - 在类中如何使用 Server.MapPath
直接在类中使用 Server.MapPath 会出现错误,这是由于类中不能直接使用 System.Web.UI.Page 的非静态函数造成的.解决方法有两种: 方法一.为类增加继承 class CFo ...