2、
procedure GetProcess(out AProcessList : TStrings);
Var
bGetProcess : Boolean;
ProcessListHandle, h : THandle;
ProcessStruct : TProcessEntry32;
a: DWORD;
begin
processListHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
try
ProcessStruct.dwSize := Sizeof(ProcessStruct);
bGetProcess := Process32First(ProcessListHandle, ProcessStruct);
While bGetProcessdo
begin
AProcessList.Add(ProcessStruct.szExeFile);
bGetProcess := Process32Next(ProcessListHandle, ProcessStruct);
end;
finally
CloseHandle(processListHandle);
end;
end;
3、
Function KillProcess(AProcessName: String): Integer;
//uses Tlhelp32;
Var
bGetProcess : Boolean;
ProcessListHandle, h : THandle;
//进程列表的句柄
ProcessStruct : TProcessEntry32;
//进程的结构,进程的信息都在这个结构里
a: DWORD;
begin
Result := 0;
processListHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
try
ProcessStruct.dwSize := Sizeof(ProcessStruct);
bGetProcess := Process32First(ProcessListHandle, ProcessStruct);
While bGetProcessdo
begin
If Uppercase(ProcessStruct.szExeFile) = Uppercase(AProcessName) then
begin
h := openprocess(PROCESS_ALL_ACCESS, TRUE, ProcessStruct.th32ProcessID);
GetExitCodeProcess(h, a);
If Integer(TerminateProcess(h, a)) <> 0 then
result := result + 1;
end;
bGetProcess := Process32Next(ProcessListHandle, ProcessStruct);
end;
finally
CloseHandle(processListHandle);
end;
end;
4、搜索一下,网上有很多
5、取MAC地址、IP地址等信息;修改IP地址
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Buttons, ShellAPI;
Const
MAX_HOSTNAME_LEN = 128;
{ from IPTYPES.H }
MAX_DOMAIN_NAME_LEN = 128;
MAX_SCOPE_ID_LEN = 256;
MAX_ADAPTER_NAME_LENGTH = 256;
MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
MAX_ADAPTER_ADDRESS_LENGTH = 8;
Type
TIPAddressString = Array[0..4*4-1] of Char;
PIPAddrString = ^TIPAddrString;
TIPAddrString = Record
Next : PIPAddrString;
IPAddress : TIPAddressString;
IPMask : TIPAddressString;
Context : Integer;
end;
PFixedInfo = ^TFixedInfo;
TFixedInfo = Record { FIXED_INFO }
HostName : Array[0..MAX_HOSTNAME_LEN+3] of Char;
do
mainName : Array[0..MAX_DOMAIN_NAME_LEN+3] of Char;
CurrentDNSServer : PIPAddrString;
DNSServerList : TIPAddrString;
NodeType : Integer;
ScopeId : Array[0..MAX_SCOPE_ID_LEN+3] of Char;
EnableRouting : Integer;
EnableProxy : Integer;
EnableDNS : Integer;
end;
PIPAdapterInfo = ^TIPAdapterInfo;
TIPAdapterInfo = Record { IP_ADAPTER_INFO }
Next : PIPAdapterInfo;
ComboIndex : Integer;
AdapterName : Array[0..MAX_ADAPTER_NAME_LENGTH+3] of Char;
Description : Array[0..MAX_ADAPTER_DESCRIPTION_LENGTH+3] of Char;
AddressLength : Integer;
Address : Array[1..MAX_ADAPTER_ADDRESS_LENGTH] of Byte;
Index : Integer;
_Type : Integer;
DHCPEnabled : Integer;
CurrentIPAddress : PIPAddrString;
IPAddressList : TIPAddrString;
GatewayList : TIPAddrString;
DHCPServer : TIPAddrString;
HaveWINS : Bool;
PrimaryWINSServer : TIPAddrString;
SecondaryWINSServer : TIPAddrString;
LeaseObtained : Integer;
LeaseExpires : Integer;
end;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Panel2: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Info: TMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
edtIP: TEdit;
edtMask: TEdit;
edtGate: TEdit;
BitBtn1: TBitBtn;
Label4: TLabel;
Shape1: TShape;
Label5: TLabel;
edtDNS1: TEdit;
edtDNS2: TEdit;
Label6: TLabel;
edtLinkName: TEdit;
procedure Button1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
Procedure GetAdapterInformation;
public
{ Public declarations }
end;
var
Form1: TForm1;
Function sendarp(ipaddr:ulong;
temp:dword;
ulmacaddr
ointer;
ulmacaddrleng
ointer) : DWord;
StdCall;
implementation
{$R *.dfm}
Function sendarp;
External 'Iphlpapi.dll' Name 'SendARP';
Function GetAdaptersInfo(AI : PIPAdapterInfo;
Var BufLen : Integer) : Integer;
StdCall;
External 'iphlpapi.dll' Name 'GetAdaptersInfo';
procedure TForm1.Button1Click(Sender: TObject);
var
myip:ulong;
mymac:array[0..5] of byte;
mymaclength:ulong;
r:integer;
begin
PageControl1.ActivePageIndex := 0;
{
myip:=inet_addr(PChar('10.0.0.1'));
mymaclength:=length(mymac);
r:=sendarp(myip, 0, @mymac, @mymaclength);
label1.caption:='errorcode:'+inttostr(r);
label2.caption:=format('%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x',[mymac[0],mymac[1],mymac[2],mymac[3],mymac[4],mymac[5]]);
}
GetAdapterInformation;
end;
procedure TForm1.GetAdapterInformation;
Var
AI,Work : PIPAdapterInfo;
Size : Integer;
Res : Integer;
I : Integer;
Function MACToStr(ByteArr : PByte;
Len : Integer) : String;
begin
Result := '';
While (Len > 0)do
begin
Result := Result+IntToHex(ByteArr^,2)+'-';
ByteArr := Pointer(Integer(ByteArr)+SizeOf(Byte));
Dec(Len);
end;
SetLength(Result,Length(Result)-1);
{ remove last dash }
end;
Function GetAddrString(Addr : PIPAddrString) : String;
begin
Result := '';
While (Addr <> nil)do
begin
Result := Result+'A: '+Addr^.IPAddress+' M: '+Addr^.IPMask+#13;
Addr := Addr^.Next;
end;
end;
Function TimeTToDateTimeStr(TimeT : Integer) : String;
Const UnixDateDelta = 25569;
{ days between 12/31/1899 and 1/1/1970 }
Var
DT : TDateTime;
TZ : TTimeZoneInformation;
Res : DWord;
begin
If (TimeT = 0) then
Result := ''
else
begin
{ Unix TIME_T is secs since 1/1/1970 }
DT := UnixDateDelta+(TimeT / (24*60*60));
{ in UTC }
{ calculate bias }
Res := GetTimeZoneInformation(TZ);
If (Res = TIME_ZONE_ID_INVALID) then
RaiseLastWin32Error;
If (Res = TIME_ZONE_ID_STANDARD) then
begin
DT := DT-((TZ.Bias+TZ.StandardBias) / (24*60));
Result := DateTimeToStr(DT)+' '+WideCharToString(TZ.StandardName);
End
else
begin
{ daylight saving time }
DT := DT-((TZ.Bias+TZ.DaylightBias) / (24*60));
Result := DateTimeToStr(DT)+' '+WideCharToString(TZ.DaylightName);
end;
end;
end;
begin
info.Lines.Clear;
Size := 5120;
GetMem(AI,Size);
Res := GetAdaptersInfo(AI,Size);
If (Res <> ERROR_SUCCESS) then
begin
SetLastError(Res);
RaiseLastWin32Error;
end;
With Info,Linesdo
begin
Work := AI;
I := 1;
Repeat
Add('');
Add('Adapter ' + IntToStr(I));
Add(' ComboIndex: '+IntToStr(Work^.ComboIndex));
Add(' Adapter name: '+Work^.AdapterName);
Add(' Description: '+Work^.Description);
Add(' Adapter address: '+MACToStr(@Work^.Address,Work^.AddressLength));
Add(' Index: '+IntToStr(Work^.Index));
Add(' Type: '+IntToStr(Work^._Type));
Add(' DHCP: '+IntToStr(Work^.DHCPEnabled));
Add(' Current IP: '+GetAddrString(Work^.CurrentIPAddress));
Add(' IP addresses: '+GetAddrString(@Work^.IPAddressList));
Add(' Gateways: '+GetAddrString(@Work^.GatewayList));
Add(' DHCP servers: '+GetAddrString(@Work^.DHCPServer));
Add(' Has WINS: '+IntToStr(Integer(Work^.HaveWINS)));
Add(' Primary WINS: '+GetAddrString(@Work^.PrimaryWINSServer));
Add(' Secondary WINS: '+GetAddrString(@Work^.SecondaryWINSServer));
Add(' Lease obtained: '+TimeTToDateTimeStr(Work^.LeaseObtained));
Add(' Lease expires: '+TimeTToDateTimeStr(Work^.LeaseExpires));
Inc(I);
Work := Work^.Next;
Until (Work = nil);
end;
FreeMem(AI);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
sIP, sMask, sGate, sDNS1, sDNS2, sLink : string;
begin
sLink := edtLinkName.Text;
sIP := edtIP.Text;
sMask := edtMask.Text;
sGate := edtGate.Text;
sDNS1 := edtDNS1.Text;
sDNS2 := edtDNS2.Text;
//net start "remote registery service"
//netsh interface ip set address ......
//net stop "remote registery service"
//IP
shellexecute(Handle, 'Open', PChar('netsh'), PChar('interface ip set address "' + sLink + '"
static ' + sIP +' ' + sMask + ' ' + sGate + ' 1'), nil, SW_HIDE);
//DNS
shellexecute(Handle, 'Open', PChar('netsh'), PChar('interface ip delete dns "' + sLink + '"
all'),nil, SW_HIDE);
shellexecute(Handle, 'Open', PChar('netsh'), PChar('interface ip set dns "' + sLink + '"
static ' + sDNS1 + ' primary'), nil, SW_HIDE);
shellexecute(Handle, 'Open', PChar('netsh'), PChar('interface ip add dns "' + sLink + '"
' + sDNS2), nil, SW_HIDE);
end;
end.