标题:
常用函数汇总[转自掰掰开发]
[打印本页]
作者:
fxh7622
时间:
2011-5-13 10:37
标题:
常用函数汇总[转自掰掰开发]
http://www.88dev.com/thread-205-1-1.html
常用函数汇总之重启动计算机
//计算机重启
function RestartWindow: bool;
var
hProcess: integer;
hToken: THandle;
Privileges: TOKEN_PRIVILEGES;
Retlen : DWORD;
begin
try
hProcess := GetCurrentProcess();
OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES or
TOKEN_ALL_ACCESS or TOKEN_QUERY ,hToken);
Privileges.PrivilegeCount :=1;
LookupPrivilegeValue(nil,'SeShutdownPrivilege',Privileges.Privileges[0].Luid);
Privileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED ;
Retlen:= 50;
AdjustTokenPrivileges(hToken,False,Privileges,0,nil,Retlen);
ExitWindowsEx(EWX_REBOOT,0);
result:= True;
except
result:= False;
end;
end;
//常用函数汇总之关闭计算机
function ExitWindow: bool;
var
hProcess: integer;
hToken: THandle;
Privileges: TOKEN_PRIVILEGES;
Retlen : DWORD;
begin
try
hProcess := GetCurrentProcess();
OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES or
TOKEN_ALL_ACCESS or TOKEN_QUERY ,hToken);
Privileges.PrivilegeCount :=1;
LookupPrivilegeValue(nil,'SeShutdownPrivilege',Privileges.Privileges[0].Luid);
Privileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED ;
Retlen:= 50;
AdjustTokenPrivileges(hToken,False,Privileges,0,nil,Retlen);
ExitWindowsEx(EWX_SHUTDOWN,0);
result:= True;
except
result:= False;
end;
end;
//常用函数汇总之得到计算机名称
function ComputerName: string;
var
CompName: array[0..MAX_COMPUTERNAME_LENGTH] of char;
dNameSize: DWORD;
sResult: string;
begin
dNameSize:= (MAX_COMPUTERNAME_LENGTH+1);
ZeroMemory(@CompName,dNameSize*sizeof(char));
GetComputerName(@CompName,dNameSize);
sResult := CompName;
Result:=sResult;
end;
//常用函数汇总之得到本机MAC地址
function NBGetAdapterAddress: string;
var
NCB : TNCB; //NetBios控制块
ADAPTER : TADAPTERSTATUS; //取网卡状态
LANAENUM : TLANAENUM; // Netbios lana
intIdx,Num : Integer; //临时变量
cRC : Char; //NetBios返回值
strTemp : String; //临时变量
begin
Result := '';
Num := 0;
Try
ZeroMemory(@NCB, SizeOf(NCB));
// Issue enum command
NCB.ncb_command := Chr(NCBENUM);
cRC := NetBios(@NCB);
// Reissue enum command
NCB.ncb_buffer := @LANAENUM;
NCB.ncb_length := SizeOf(LANAENUM);
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Reset adapter
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBRESET);
NCB.ncb_lana_num := LANAENUM.lana[Num];
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Get adapter address
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBASTAT);
NCB.ncb_lana_num := LANAENUM.lana[Num];
StrPCopy(NCB.ncb_callname, '*');
NCB.ncb_buffer := @ADAPTER;
NCB.ncb_length := SizeOf(ADAPTER);
cRC := NetBios(@NCB);
// Convert it to string
strTemp := '';
For intIdx := 0 To 5 Do
strTemp := strTemp + InttoHex(Integer(ADAPTER.adapter_address[intIdx]),2);
Result := strTemp;
Finally
End;
end;
http://www.88dev.com/forum-viewthread-tid-205-fromuid-40.html
欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/)
Powered by Discuz! 6.0.0