Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 05-09-2015
Avatar de kurono
[kurono] kurono is offline
Miembro Premium
 
Registrado: jul 2007
Ubicación: Republica Dominicana
Posts: 1.126
Poder: 18
kurono Va por buen camino
hace tiempo que tenia la misma necesidad que tu y pude hacerlo gracia a este codigo

Código Delphi [-]
function IsWinNT: boolean;
var
  OSV: OSVERSIONINFO;
begin
  OSV.dwOSVersionInfoSize := sizeof(osv);
  GetVersionEx(OSV);
  result := OSV.dwPlatformId = VER_PLATFORM_WIN32_NT;
end;

function CmdExec(Cmd: string): string;
var
  Buffer: array[0..4096] of Char;
  si: STARTUPINFO;
  sa: SECURITY_ATTRIBUTES;
  sd: SECURITY_DESCRIPTOR;
  pi: PROCESS_INFORMATION;
  newstdin, newstdout, read_stdout, write_stdin: THandle;
  exitcod, bread, avail: Cardinal;
begin
  Result:= '';
  if IsWinNT then
  begin
    InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION);
    SetSecurityDescriptorDacl(@sd, true, nil, false);
    sa.lpSecurityDescriptor := @sd;
  end
  else sa.lpSecurityDescriptor := nil;
  sa.nLength := sizeof(SECURITY_ATTRIBUTES);
  sa.bInheritHandle := TRUE;
  if CreatePipe(newstdin, write_stdin, @sa, 0) then
  begin
    if CreatePipe(read_stdout, newstdout, @sa, 0) then
    begin
      GetStartupInfo(si);
      with si do
      begin
        dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
        wShowWindow := SW_HIDE;
        hStdOutput := newstdout;
        hStdError := newstdout;
        hStdInput := newstdin;
      end;
      Fillchar(Buffer, SizeOf(Buffer), 0);
      GetEnvironmentVariable('COMSPEC', @Buffer, SizeOf(Buffer) - 1);
      StrCat(@Buffer,PChar(' /c ' + Cmd));
      if CreateProcess(nil, @Buffer, nil, nil, TRUE, CREATE_NEW_CONSOLE, nil, nil, si, pi) then
      begin
        repeat
          PeekNamedPipe(read_stdout, @Buffer, SizeOf(Buffer) - 1, @bread, @avail, nil);
          if bread > 0 then
          begin
            Fillchar(Buffer, SizeOf(Buffer), 0);
            ReadFile(read_stdout, Buffer, bread, bread, nil);
            Result:= Result + String(PChar(@Buffer));
          end;
          Application.ProcessMessages;
          GetExitCodeProcess(pi.hProcess, exitcod);
        until (exitcod <> STILL_ACTIVE) and (bread = 0);
      end;
      CloseHandle(read_stdout);
      CloseHandle(newstdout);
    end;
    CloseHandle(newstdin);
    CloseHandle(write_stdin);
  end;
end;

ejemplo de uso

begin

ShowMessage(CmdExec('dir c:\'));
ShowMessage(CmdExec('netstat -a -n'));

end;
end.
Responder Con Cita
  #2  
Antiguo 24-04-2016
Delphi01 Delphi01 is offline
Miembro
 
Registrado: nov 2015
Ubicación: Barcelona,España
Posts: 68
Poder: 9
Delphi01 Va por buen camino
hola [kurono] he probado lo que pusiste pero los mensajes me salieron en chino y caracteres raros !!!!

me podrías decirme porque por favor ? Gracias .
Responder Con Cita
  #3  
Antiguo 25-04-2016
Avatar de kurono
[kurono] kurono is offline
Miembro Premium
 
Registrado: jul 2007
Ubicación: Republica Dominicana
Posts: 1.126
Poder: 18
kurono Va por buen camino
en que version de windows esta ejecutando la funcion que te pase
Responder Con Cita
  #4  
Antiguo 26-10-2016
clauxs88 clauxs88 is offline
Miembro
 
Registrado: feb 2013
Ubicación: Asuncion
Posts: 12
Poder: 0
clauxs88 Va por buen camino
Salen Letras en chino y caracteres raros al ejecutar la funcion

Cita:
Empezado por Delphi01 Ver Mensaje
hola [kurono] he probado lo que pusiste pero los mensajes me salieron en chino y caracteres raros !!!!

me podrías decirme porque por favor ? Gracias .
A mi tambien me pasa lo mismo, lo compile en Delphi XE. Algo asi,,

਍潃普杩牵捡ꉩ偉搠⁥楗摮睯൳ഊ
਍摁灡慴潤⁲敤䔠桴牥敮⁴瑅敨湲瑥ഺഊ
Responder Con Cita
  #5  
Antiguo 28-10-2016
Avatar de kurono
[kurono] kurono is offline
Miembro Premium
 
Registrado: jul 2007
Ubicación: Republica Dominicana
Posts: 1.126
Poder: 18
kurono Va por buen camino
ese codigo yo lo compile en delphi 7 y ejecutado en windows xp y funcionaba perfecto
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
como ejecutar comandos de manera remota maikeloh Redes 2 05-03-2007 21:03:31
comandos de impresion federicorl Impresión 4 07-09-2006 22:03:49
Ejecutar comandos en aplicación externa José Craviotto Varios 1 03-02-2006 13:21:28
Ejecutar comandos AT(modem)desde Delphi rodrigo iñiguez Internet 1 26-01-2004 16:03:48
Ejecutar comandos del DOS? Carlos Arevalo Varios 3 12-11-2003 07:50:41


La franja horaria es GMT +2. Ahora son las 11:09:54.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi