www.pudn.com > 自动计划(autoplan)源代码___强烈推荐 .rar > Unt_Fun.pas


unit Unt_Fun; 
 
interface 
   uses Windows, SysUtils, Registry, WinSock, WinInet,auHTTP, 
        inifiles,auAutoUpgrader,Dialogs; 
var 
  timeLeave:integer; 
    ver:string; 
function LocalIP : string; 
function InternetConnected: Boolean; 
function CheckWEB():BOOLEAN; 
function GetLocaName():string; 
function GetLeaveTime():string; 
function GetNewVer():boolean; 
Function ExitWindows(RebootParam:Longword):Boolean; 
implementation 
   uses unt_main; 
 
Function ExitWindows(RebootParam:Longword):Boolean; 
 var 
   TTokenHd:THandle; 
   TTokeyPvg:TTokenPrivileges; 
   cbtpPrevious:Dword; 
   pcbtpPreviousRequired:Dword; 
 Const 
   SE_SHUTDOWN_NAME='SeshutdownPrivilege'; 
 Begin 
   //判断系统是否是Win2000,NT还是WinXP 
   if Win32Platform=VER_PLATFORM_WIN32_NT then 
     Begin 
       //得到当前进程的存取令牌句柄,以便得到关机特权 
       Result:=OpenProcessToken(GetCurrentProcess, 
                 TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, 
                 TTOKENHD); 
       if Result then 
         Begin 
           //得到关机特权的LUID(局部标识符) 
           Result:=LookupPrivilegeValue(nil,SE_SHUTDOWN_NAME, 
           TTokeyPvg.Privileges[0].luid); 
           TTokeyPvg.PrivilegeCount:=1; 
           TTokeyPvg.privileges[0].Attributes:=SE_PRIVILEGE_ENABLED; 
           cbtpPrevious:=Sizeof(TTokeyPvg); 
           pcbtpPreviousRequired:=0; 
           //得到该进程的关机特权 
           if Result then 
             Windows.AdjustTokenPrivileges(TTokenHd,False,TTokeyPvg,cbtpPrevious, 
                                TTokeyPvg,pcbtpPreviousRequired); 
         End; 
     End; 
   Result:=ExitWindowsEx(RebootParam,32); 
 End; 
{================================================================= 
 功  能:  检测计算机是否上网 
 参  数:  无 
 返回值:  成功:  True  失败: False; 
 备  注:  uses Wininet 
 版  本:  1.0  2003/08/11 
=================================================================} 
function InternetConnected: Boolean; 
const 
  // local system uses a modem to connect to the Internet. 
  INTERNET_CONNECTION_MODEM      = 1; 
  // local system uses a local area network to connect to the Internet. 
  INTERNET_CONNECTION_LAN        = 2; 
  // local system uses a proxy server to connect to the Internet. 
  INTERNET_CONNECTION_PROXY      = 4; 
  // local system's modem is busy with a non-Internet connection. 
  INTERNET_CONNECTION_MODEM_BUSY = 8; 
var 
  dwConnectionTypes : DWORD; 
begin 
  dwConnectionTypes := INTERNET_CONNECTION_MODEM+ INTERNET_CONNECTION_LAN 
    + INTERNET_CONNECTION_PROXY; 
  Result := InternetGetConnectedState(@dwConnectionTypes, 0); 
end; 
 
function CheckWEB():BOOLEAN; 
BEGIN 
    if InternetCheckConnection('http://www.163.com', 1, 0) then 
      Result := TRUE 
    else 
      Result := FALSE; 
END; 
function GetLocaName():string; 
var 
  Buffer: array[0..MAX_PATH] of Char; 
  Size: Cardinal; 
begin 
  Size := SizeOf(Buffer); 
  GetComputerName(Buffer, Size); 
  Result := Buffer; 
end; 
//得到IP地址代码如下: 
function LocalIP : string; 
type 
  TaPInAddr = array [0..10] of PInAddr; 
  PaPInAddr = ^TaPInAddr; 
var 
  phe  : PHostEnt; 
  pptr : PaPInAddr; 
  Buffer : array [0..63] of char; 
  I    : Integer; 
  GInitData: TWSADATA; 
begin 
  WSAStartup($101, GInitData); 
  Result := ''; 
  GetHostName(Buffer, SizeOf(Buffer));    //获得主机名 
  phe :=GetHostByName(buffer); 
  if phe = nil then Exit;                 //如果是空则退出 
    pptr := PaPInAddr(Phe^.h_addr_list); 
    I := 0; 
    while pptr^[I] <> nil do begin 
      result:=StrPas(inet_ntoa(pptr^[I]^)); 
      Inc(I); 
    end; 
    WSACleanup; 
end; 
function GetLeaveTime():string; 
var 
  Reg: TRegistry; 
begin 
  Reg := TRegistry.Create; 
  try 
    Reg.RootKey := HKEY_LOCAL_MACHINE; 
    if Reg.OpenKey('\Software\AutoPlan', True) then 
    begin 
      Reg.OpenKey('TimeLeave',True); 
      Auto_Plan.Lb_TimeTotal.Caption :='00:'+ Format('%.2d',[Reg.readinteger('Time')]); 
    end; 
  finally 
    Reg.CloseKey; 
    Reg.Free ; 
  end; 
end; 
function GetNewVer():boolean; 
var 
  InfFile:string; 
  auAutoUpgrader1 : TauAutoUpgrader; 
  MyIniFile: TIniFile; 
begin 
  MyIniFile := TIniFile.Create('ver.dll'); 
  with MyIniFile do 
  begin 
    auAutoUpgrader1 := TauAutoUpgrader.Create(auAutoUpgrader1); 
    Auto_Plan.strver := MyIniFile.ReadString('ver','ver','1.0'); 
    auAutoUpgrader1.InfoFileURL := MyIniFile.ReadString('update','update',''); 
    auAutoUpgrader1.VersionNumber := Auto_Plan.strver; 
  end; 
  MyIniFile.Free; 
  Auto_Plan.HavNewVer := true; 
  auAutoUpgrader1.OnNoUpdateAvailable := Auto_Plan.OnNoNewVer; 
  auAutoUpgrader1.CheckUpdate; 
end; 
procedure CheckNew(Sender: TObject); 
begin 
end; 
end.