📄 getpcinfo.~pas
字号:
VER_PLATFORM_WIN32_WINDOWS:
begin
result:=1;
end;
end;
end;
function getdnsstr(sKey,sItem:string):string;
var
reg:TRegistry;
tmpstr:string;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey(sKey, false) then
begin
tmpstr:=reg.ReadString(sItem);
Reg.CloseKey;
end;
result:=tmpstr;
finally
Reg.Free;
end;
end;
procedure GetDNS;
begin
if GetWinVersion=0 then
begin
s_nameserver:=getdnsstr('SYSTEM\CurrentControlSet\Services\Tcpip\Parameters','NameServer');
s_domain:=getdnsstr('SYSTEM\CurrentControlSet\Services\Tcpip\Parameters','Domain');
s_miaoshu:=getdnsstr('SYSTEM\CurrentControlSet\Services\lanmanserver\parameters','srvcomment');
end
else if GetWinVersion =1 then
begin
s_nameserver:=getdnsstr('SYSTEM\CurrentControlSet\Services\VxD\MSTCP','NameServer');
s_domain:=getdnsstr('SYSTEM\CurrentControlSet\Services\VxD\MSTCP','Domain');
s_miaoshu:=getdnsstr('SYSTEM\CurrentControlSet\Services\lanmanserver\parameters','srvcomment');
end;
end;
function getip(name:string):string;
var
aa:TWsadata;
host:Phostent;
bb:string;
begin
bb:='';
wsastartup(2,aa);
host:=gethostbyname(pchar(name));
if host <>nil then
begin
with host^ do
bb:=format('%d.%d.%d.%d',[BYTE(h_addr^[0]),BYTE(h_addr^[1]),BYTE(h_addr^[2]),BYTE(h_addr^[3])]);
end;
wsacleanup;
result:=bb;
end;
procedure TForm1.huoquMem;
var
tmpstr:string;
tmpint:int64;
i:integer;
begin
s_memsize[0]:='';
s_memsize[1]:='';
s_memsize[2]:='';
s_memsize[3]:='';
WmiQuery1.Active:=false;
WmiQuery1.WQL.Clear;
WmiQuery1.WQL.Text:='select * FROM Win32_PhysicalMemory';
// WmiConnection1.Connected:=true;
WmiQuery1.Active:=true;
i:=0;
while not WmiQuery1.Eof do
begin
tmpstr:=inttostr(WmiQuery1.FieldByname('Capacity').AsInteger div 1048576);
if i<=8 then
begin
s_pcinfo[i].MemSize :=tmpstr+'M';
end;
inc(i);
WmiQuery1.Next;
end;
end;
procedure TForm1.GetDiskSize;
var
tmpstr:string;
i:integer;
tmpint:int64;
tmpfloat:real;
begin
WmiQuery1.Active:=false;
WmiQuery1.WQL.Clear;
WmiQuery1.WQL.Text:='select * FROM Win32_DiskDrive';
WmiConnection1.Connected:=true;
WmiQuery1.Active:=true;
i:=0;
while not WmiQuery1.Eof do
begin
tmpstr:=WmiQuery1.FieldByname('Size').AsString;
tmpint:=strtoint64(tmpstr);
tmpfloat:=tmpint / 1073741824;
//tmpfloat:=tmpint div 1024;
if i <=8 then
begin
s_pcinfo[i].DiskSize:=format('%f G',[tmpfloat]);
s_pcinfo[i].DiskType := WmiQuery1.FieldByname('Model').AsString;
s_pcinfo[i].DiskID :=WmiQuery1.FieldByname('PNPDeviceID').AsString ;
end;
WmiQuery1.Next;
inc(i);
end;
end;
procedure TForm1.GetNetWork;
var
tmpstr:string;
i:integer;
begin
WmiQuery1.Active:=false;
WmiQuery1.WQL.Clear;
WmiQuery1.WQL.Text:='select * FROM Win32_NetworkAdapterConfiguration';
WmiConnection1.Connected:=true;
WmiQuery1.Active:=true;
i:=0;
while not WmiQuery1.Eof do
begin
if (i <=8) and (WmiQuery1.FieldByname('IPEnabled').AsBoolean =true) then
begin
s_pcinfo[i].MACAddress :=WmiQuery1.FieldByname('MACAddress').AsString;
s_pcinfo[i].NetDiscrip := WmiQuery1.FieldByname('Description').AsString;
s_pcinfo[i].IPAddress :=WmiQuery1.FieldByname('IPAddress').AsString ;
s_pcinfo[i].WINSPrimaryServer :=WmiQuery1.FieldByname('WINSPrimaryServer').AsString ;
s_pcinfo[i].WINSSecondaryServer :=WmiQuery1.FieldByname('WINSSecondaryServer').AsString ;
s_pcinfo[i].DNSServerSearchOrder :=WmiQuery1.FieldByname('DNSServerSearchOrder').AsString ;
s_pcinfo[i].DefaultIPGateway :=WmiQuery1.FieldByname('DefaultIPGateway').AsString ;
end;
WmiQuery1.Next;
inc(i);
end;
end;
procedure TForm1.Getcpuinfo;
var
tmpstr:string;
i:integer;
begin
WmiQuery1.Active:=false;
WmiQuery1.WQL.Clear;
WmiQuery1.WQL.Text:='select * FROM Win32_Processor';
WmiConnection1.Connected:=true;
WmiQuery1.Active:=true;
i:=0;
while not WmiQuery1.Eof do
begin
if (i <=8) then
begin
s_pcinfo[i].cpudescription :=WmiQuery1.FieldByname('description').AsString;
s_pcinfo[i].cpuCurrentClockSpeed := WmiQuery1.FieldByname('CurrentClockSpeed').AsString;
s_pcinfo[i].cpuDataWidth :=WmiQuery1.FieldByname('DataWidth').AsString+'位' ;
s_pcinfo[i].cpuManufacturer :=WmiQuery1.FieldByname('Manufacturer').AsString ;
s_pcinfo[i].cpuProcessorId :=WmiQuery1.FieldByname('ProcessorId').AsString ;
end;
WmiQuery1.Next;
inc(i);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
Panel1.Caption :='正在采集数据,请等待....';
Panel1.Visible :=true;
for i:=0 to 8 do
begin
s_pcinfo[i].cpudescription :='';
s_pcinfo[i].cpuCurrentClockSpeed :='';
s_pcinfo[i].cpuDataWidth :='';
s_pcinfo[i].cpuManufacturer :='';
s_pcinfo[i].cpuProcessorId :='';
s_pcinfo[i].MACAddress :='';
s_pcinfo[i].NetDiscrip :='';
s_pcinfo[i].IPAddress :='';
s_pcinfo[i].WINSPrimaryServer :='';
s_pcinfo[i].WINSSecondaryServer :='';
s_pcinfo[i].DNSServerSearchOrder :='';
s_pcinfo[i].DefaultIPGateway :='';
s_pcinfo[i].DiskType :='';
s_pcinfo[i].DiskID :='';
s_pcinfo[i].DiskSize :='';
s_pcinfo[i].MemSize :='';
end;
//DateTime := Time;
riqi:=DateToStr(Date);
infolist.Lines.Clear ;
getnames;
GetDNS;
huoquMem;
GetDiskSize;
GetNetWork;
GetcpuInfo;
infolist.Lines.Add('计算机名称:');
infolist.Lines.Add (pc_name);
infolist.Lines.Add('工作组名:') ;
infolist.Lines.Add (s_nameserver);
infolist.Lines.Add('计算机域名:') ;
infolist.Lines.Add (s_domain);
infolist.Lines.Add('计算机描述:') ;
infolist.Lines.Add (s_miaoshu);
for i:=0 to 8 do
begin
if s_pcinfo[i].cpudescription <>'' then
begin
infolist.Lines.Add('CPU描述'+inttostr(i));
infolist.Lines.Add(s_pcinfo[i].cpudescription);
infolist.Lines.Add('CPU时钟速度');
infolist.Lines.Add(s_pcinfo[i].cpuCurrentClockSpeed);
infolist.Lines.Add('CPU数据宽度');
infolist.Lines.Add(s_pcinfo[i].cpuDataWidth);
infolist.Lines.Add('CPU厂家');
infolist.Lines.Add(s_pcinfo[i].cpuManufacturer);
infolist.Lines.Add('CPU序列号');
infolist.Lines.Add(s_pcinfo[i].cpuProcessorId);
end;
end;
for i:=0 to 8 do
begin
if s_pcinfo[i].MACAddress <>'' then
begin
infolist.Lines.Add('网卡地址'+inttostr(i));
infolist.Lines.Add(s_pcinfo[i].MACAddress);
infolist.Lines.Add('网卡描述');
infolist.Lines.Add(s_pcinfo[i].NetDiscrip);
infolist.Lines.Add('IP地址');
infolist.Lines.Add(s_pcinfo[i].IPAddress);
infolist.Lines.Add('WINS主服务器');
infolist.Lines.Add(s_pcinfo[i].WINSPrimaryServer);
infolist.Lines.Add('WINS第二服务器');
infolist.Lines.Add(s_pcinfo[i].WINSSecondaryServer);
infolist.Lines.Add('DNS服务器查找顺序');
infolist.Lines.Add(s_pcinfo[i].DNSServerSearchOrder);
infolist.Lines.Add('默认网关');
infolist.Lines.Add(s_pcinfo[i].DefaultIPGateway);
end;
end;
for i:=0 to 8 do
begin
if s_pcinfo[i].DiskID <>'' then
begin
infolist.Lines.Add('硬盘类型'+inttostr(i));
infolist.Lines.Add(s_pcinfo[i].DiskType);
infolist.Lines.Add('硬盘序列号');
infolist.Lines.Add(s_pcinfo[i].DiskID);
infolist.Lines.Add('硬盘大小');
infolist.Lines.Add(s_pcinfo[i].DiskSize);
end;
end;
for i:=0 to 8 do
begin
if s_pcinfo[i].MemSize <>'' then
begin
infolist.Lines.Add('内存'+inttostr(i)+'大小');
infolist.Lines.Add( s_pcinfo[i].MemSize);
end;
end;
// CopyDbToExcel;
infolist.Lines.Add('采集日期:') ;
infolist.Lines.Add (riqi);
Button2.Enabled :=TRUE;
Panel1.Visible :=false;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
sendmsg:string;
begin
Panel1.Caption :='发送邮件到管理员,请等待....';
Panel1.Visible :=true;
s_pcyjid:=Edit1.Text ;
s_ossn:=MaskEdit1.Text ;
With TDS2Excel.Create do
Try
Save2File(True);
finally
Free;
end;
SMTP1.Host := '10.142.168.8';
SMTP1.Port := 25;
SMTP1.UserID := 'sjljl@xmep.com.cn';
SMTP1.Connect;
SMTP1.PostMessage.FromAddress :='sjljl@xmep.com.cn';
SMTP1.PostMessage.FromName := '计算机信息采集工具';
SMTP1.PostMessage.Subject := pc_name+'计算机信息';
sendmsg:= pc_name+s_miaoshu+'计算机信息';
SMTP1.PostMessage.ToAddress.Clear ;
SMTP1.PostMessage.ToAddress.Add('sjljl@xmep.com.cn');
SMTP1.PostMessage.ToAddress.Add('hczj@xmep.com.cn');
SMTP1.PostMessage.ToAddress.Add('sjcjw@xmep.com.cn');
SMTP1.PostMessage.Body.Clear ;
SMTP1.PostMessage.Body.Add(sendmsg);
SMTP1.PostMessage.Attachments.Clear ;
SMTP1.PostMessage.Attachments.Add(localdir+trim(pc_name)+'.xls');
SMTP1.SendMail;
SMTP1.Disconnect;
Panel1.Visible :=false;
Application.MessageBox('邮件发送成功!','系统提示',0);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
Panel1.Visible :=false;
localdir:=ExtractFilePath(Application.ExeName);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -