PDA

View Full Version : سوال: اوردن نام كامپيوتر به داخل برنامه



cheshm
جمعه 06 آذر 1388, 14:31 عصر
salam chetori mishe nam computer ro be dakhel barname avord(aztariq kod)
lotfan be dadam brsid.:گریه:

joker
جمعه 06 آذر 1388, 16:03 عصر
API :
GetcomputerName

Sample Delphi :)



//-----------------------------------------\\
// GetCompurterName(); \\
// Example : \\
// \\
// Edit1.text := GCN(); \\
//-----------------------------------------\\

function GCN : string;
const
cnMaxCompNameLen = 254;
var
sCompName : string;
dwCompNameLen : DWord;
begin
dwCompNameLen := cnMaxCompNameLen-1;
SetLength( sCompName, cnMaxCompNameLen );
GetcomputerName( PChar( sCompName ),
dwCompNameLen );

SetLength( sCompName, dwcompNameLen );
Result := sCompName;
end;

debugger
جمعه 06 آذر 1388, 16:29 عصر
using System.Management;
using System.Runtime.InteropServices;

class Class1
{
[System.Runtime.InteropServices.DllImport("Kernel32")]
static extern unsafe bool GetComputerName(byte* lpBuffer, long* nSize);


[STAThread]
static void Main(string[] args)
{
byte[] buffor = new byte[512];
long size = buffor.Length;
unsafe
{
long* pSize = &size;
fixed (byte* pBuffor = buffor)
{
GetComputerName(pBuffor, pSize);
}
}
System.Text.Encoding textEnc = new System.Text.ASCIIEncoding();
System.Console.WriteLine("Computer name: {0}", textEnc.GetString(buffor));
}
}