Mac Adresini Nasıl alabiliriz?
Forum kuralları
Forum kurallarını okuyup, uyunuz!
Forum kurallarını okuyup, uyunuz!
Mac Adresini Nasıl alabiliriz?
Acaba bilgisayarlarda olan ethernet kartlarının mac adreslerini alıp programımız içinde kullanabileceğimiz bir program yada compenent var mı ???
- coskundeniz
- Üye
- Mesajlar: 22
- Kayıt: 20 Ara 2003 11:36
Aşağıda kod işini görecektir
Kod: Tümünü seç
function GetPrimaryNicMacAddress : string;
type
TGUID = record
A, B: word;
D, M, S: word;
MAC: array[1..6] of byte;
end;
var
UuidCreateFunc: function(var guid: TGUID): HResult; stdcall;
handle: THandle;
g: TGUID;
WinVer: _OSVersionInfoA;
i: integer;
begin
WinVer.dwOSVersionInfoSize := sizeof(WinVer);
getversionex(WinVer);
handle := LoadLibrary('RPCRT4.DLL');
if WinVer.dwMajorVersion >= 5 then {Windows 2000 }
@UuidCreateFunc := GetProcAddress(Handle, 'UuidCreateSequential')
else
@UuidCreateFunc := GetProcAddress(Handle, 'UuidCreate');
if UuidCreateFunc(g) = 0 then
begin
Result := '';
for i := 1 to 6 do
begin
if Result <> '' then Result := Result + '-';
result := result + IntToHex(g.MAC[i], 2);
end;
end else result := '00-00-00-00-00-00';
end;
Coderlord sizin gönderdiğiniz artikellı zaten biliyorum okudum. Saolsun coskundenizin verdiği kodtaki GUID yöntemini de konumuştum. Arama yapmamış değilim. merakım şudur. ipconfig /all komutunun nasıl gönderirim sonuçlarını nasıl alırım programıma onu merak ediyorum....
St. NonStop
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
Program çalıştırma ile ilgili kodu sitede bulabilirsin, onu vermiyorum.
1. yöntem: çalıştırırken "ipconfig /all > c:\ipconfig.txt" yapar ve ipconfig.txt içini okuyarak parse edersin. Bu komut ile ipconfig / all'un çıktısı c:\ipconfig.txt ye yazılacaktır.
2. yöntem:
http://delphi.about.com/cs/adptips2001/ ... 0201_2.htm
1. yöntem: çalıştırırken "ipconfig /all > c:\ipconfig.txt" yapar ve ipconfig.txt içini okuyarak parse edersin. Bu komut ile ipconfig / all'un çıktısı c:\ipconfig.txt ye yazılacaktır.
2. yöntem:
http://delphi.about.com/cs/adptips2001/ ... 0201_2.htm
Bu da doğrudan bir TMemo içine çıktıyı gönderiyor.From Zarko Gajic,
Your Guide to Delphi Programming.
FREE Newsletter. Sign Up Now!
The example runs 'chkdsk.exe c:\' and displays the output to Memo1.
Put a TMemo (Memo1) and a TButton (Button1) on your form. Put this code in the OnCLick event procedure for Button1:
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject) ;
procedure RunDosInMemo(DosApp:String;AMemo:TMemo) ;
const
ReadBuffer = 2400;
var
Security : TSecurityAttributes;
ReadPipe,WritePipe : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : DWord;
Apprunning : DWord;
begin
With Security do begin
nlength := SizeOf(TSecurityAttributes) ;
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if Createpipe (ReadPipe, WritePipe,
@Security, 0) then begin
Buffer := AllocMem(ReadBuffer + 1) ;
FillChar(Start,Sizeof(Start),#0) ;
start.cb := SizeOf(start) ;
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;
if CreateProcess(nil,
PChar(DosApp),
@Security,
@Security,
true,
NORMAL_PRIORITY_CLASS,
nil,
nil,
start,
ProcessInfo)
then
begin
repeat
Apprunning := WaitForSingleObject
(ProcessInfo.hProcess,100) ;
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT) ;
Repeat
BytesRead := 0;
ReadFile(ReadPipe,Buffer[0],
ReadBuffer,BytesRead,nil) ;
Buffer[BytesRead]:= #0;
OemToAnsi(Buffer,Buffer) ;
AMemo.Text := AMemo.text + String(Buffer) ;
until (BytesRead < ReadBuffer) ;
end;
FreeMem(Buffer) ;
CloseHandle(ProcessInfo.hProcess) ;
CloseHandle(ProcessInfo.hThread) ;
CloseHandle(ReadPipe) ;
CloseHandle(WritePipe) ;
end;
end;
begin {button 1 code}
RunDosInMemo('chkdsk.exe c:\',Memo1) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Kod: Tümünü seç
Memo1->Clear();
//create pipe for the console stdout
SECURITY_ATTRIBUTES sa;
ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES));
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle=true;
sa.lpSecurityDescriptor=NULL;
HANDLE ReadPipeHandle;
HANDLE WritePipeHandle; // not used here
if(!CreatePipe(&ReadPipeHandle,&WritePipeHandle,&sa,0))
RaiseLastWin32Error();
//Create a Console
STARTUPINFO si;
ZeroMemory(&si,sizeof(STARTUPINFO));
si.cb=sizeof(STARTUPINFO);
si.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.wShowWindow=SW_HIDE;
si.hStdOutput=WritePipeHandle;
si.hStdError=WritePipeHandle;
PROCESS_INFORMATION pi;
ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
if(!CreateProcess(CBox1->Text.c_str(),CBox2->Text.c_str(),NULL,NULL,true,0,NULL,NULL,&si,&pi))
RaiseLastWin32Error();
//Read from pipe
char Data[1024];
for (;;)
{
DWORD BytesRead;
DWORD TotalBytes;
DWORD BytesLeft;
//Check for the presence of data in the pipe
if(!PeekNamedPipe(ReadPipeHandle,Data,sizeof(Data),&BytesRead,
&TotalBytes,&BytesLeft))RaiseLastWin32Error();
//If there is bytes, read them
if(BytesRead)
{
if(!ReadFile(ReadPipeHandle,Data,sizeof(Data)-1,&BytesRead,NULL))
RaiseLastWin32Error();
Data[BytesRead]='\0';
Memo1->Lines->Add(AnsiString(Data));
}
else
{
//Is the console app terminated?
if(WaitForSingleObject(pi.hProcess,0)==WAIT_OBJECT_0)break;
}
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(ReadPipeHandle);
CloseHandle(WritePipeHandle);
Kodu biraz geliştirdim. windows98 xp ve 2000 lerde çalışabilecek şekle getirmeye çalıştım.
Kod: Tümünü seç
AnsiString Path;
int OSVersion;
Memo1->Clear();
TRegistry *Reg = new TRegistry;
try
{
Reg->RootKey = HKEY_LOCAL_MACHINE;
if (Reg->OpenKey("\\Software\\Microsoft\\Windows NT\\CurrentVersion", false))
{
if (Reg->ValueExists("SystemRoot"))
{
Path = Reg->ReadString("SystemRoot");
OSVersion = 1;
}
else
{
Reg->CloseKey();
if (Reg->OpenKey("\\Software\\Microsoft\\Windows\\CurrentVersion", false))
{
if (Reg->ValueExists("SystemRoot"))
{
Path = Reg->ReadString("SystemRoot");
OSVersion = 0;
}
}
}
Reg->CloseKey();
}
//create pipe for the console stdout
SECURITY_ATTRIBUTES sa;
ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES));
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle=true;
sa.lpSecurityDescriptor=NULL;
HANDLE ReadPipeHandle;
HANDLE WritePipeHandle; // not used here
if(!CreatePipe(&ReadPipeHandle,&WritePipeHandle,&sa,0))
RaiseLastWin32Error();
//Create a Console
STARTUPINFO si;
ZeroMemory(&si,sizeof(STARTUPINFO));
si.cb=sizeof(STARTUPINFO);
si.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.wShowWindow=SW_HIDE;
si.hStdOutput=WritePipeHandle;
si.hStdError=WritePipeHandle;
PROCESS_INFORMATION pi;
ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
if (OSVersion == 1)
{
Path = Path+"\\system32\\ipconfig.exe";
if(!CreateProcess(Path.c_str(), "ipconfig /all",NULL,NULL,true,0,NULL,NULL,&si,&pi))
RaiseLastWin32Error();
}
else if (OSVersion == 0)
{
Path = Path+"\\ipconfig.exe";
if(!CreateProcess(Path.c_str(), "ipconfig /all",NULL,NULL,true,0,NULL,NULL,&si,&pi))
RaiseLastWin32Error();
}
//Read from pipe
char Data[1024];
for (;;)
{
DWORD BytesRead;
DWORD TotalBytes;
DWORD BytesLeft;
//Check for the presence of data in the pipe
if(!PeekNamedPipe(ReadPipeHandle,Data,sizeof(Data),&BytesRead,
&TotalBytes,&BytesLeft))RaiseLastWin32Error();
//If there is bytes, read them
if(BytesRead)
{
if(!ReadFile(ReadPipeHandle,Data,sizeof(Data)-1,&BytesRead,NULL))
RaiseLastWin32Error();
Data[BytesRead]='\0';
Memo1->Lines->Add(AnsiString(Data));
}
else
{
//Is the console app terminated?
if(WaitForSingleObject(pi.hProcess,0)==WAIT_OBJECT_0)break;
}
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(ReadPipeHandle);
CloseHandle(WritePipeHandle);
}
__finally
{
delete Reg;
}
St. NonStop
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi