IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API, COM et SDKs Delphi Discussion :

lancer un batch avec CreateProcess et le réduire !! [FAQ]


Sujet :

API, COM et SDKs Delphi

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 36
    Points : 18
    Points
    18
    Par défaut lancer un batch avec CreateProcess et le réduire !!
    voilà, je lance un fichier bat avec CreateProcess, et je ne vois pas quel parametre changer pour que mon fichier bat soit lancer en réduit.
    si quelqu'un a une idée ...

    Merci ^_^

    mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    CreateProcess(nil,PChar(monfichier.bat),nil,nil,true,0,nil,nil,StartInfo,ProcessInformation)

  2. #2
    Rédacteur
    Avatar de Pedro
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    5 411
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 5 411
    Points : 8 078
    Points
    8 078
    Par défaut
    Salut

    http://delphi.developpez.com/faq/?pa...terapplication avec les paramètres de ShowCmd
    Pedro
    Aucune réponse aux sollicitations techniques par MP

    Faut pas attendre d'en avoir besoin pour s'en servir... (Lucien Stéphane)

    Les pages Source C'est bon. Mangez-en!
    Le défi Delphi
    Règles du forum - FAQ Delphi - Pensez au chtit
    Aéroclub Bastia Saint-Exupéry

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    désolé, je peux paraitre un peu con ( beaucoup je suis sur ^_^)
    mais j essaye de mettre SW_SHOWMINIMIZED, et ça ne marche a aucun endroit de mon createprocess ....

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    pour etre plsu précis, je veux lancer un batch en mode réduit et attendre que le processus soit finit.
    pour celà j'ai récupérer la fonction :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    function LanceAppliAttenteFin(NomFichier:string):boolean;
     
    var
      StartInfo : TStartupInfo;
      ProcessInformation : TProcessInformation;
    begin
      result:=true;
      ZeroMemory(@StartInfo, sizeof(StartInfo)); // remplie de 0 StartInfo
      StartInfo.cb:=sizeof(StartInfo);
      if CreateProcess(nil,PChar(NomFichier),nil,nil,true,0,nil,nil,StartInfo,ProcessInformation)
      then WaitForSingleObject(ProcessInformation.hProcess, INFINITE)// attend que l'application désignée par le handle ProcessInformation.hProcess soit terminée
      else result:=false;
    end;
    mais ça ne me permet pas de lancer le bath en mode reduit ....

    si quelqu'un a une idée ^_^

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    personne n entrevoit la solution svp ??
    merci ^_^

  6. #6
    Membre chevronné

    Profil pro
    Chef de Projet / Développeur
    Inscrit en
    Juin 2002
    Messages
    598
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chef de Projet / Développeur
    Secteur : Santé

    Informations forums :
    Inscription : Juin 2002
    Messages : 598
    Points : 2 020
    Points
    2 020
    Par défaut
    Salut,

    Voilà un bout de code trouvé sur internet (une recherche sur google devrait donner accès au source complet).

    La fenêtre n'apparait pas en minimisée, mais n'apparait pas du tout !
    Au final la fonction retourne le ERRORLEVEL, ainsi que la sortie console dans une TStringList (qui doit avoir été créé par l'appelant) - un peu dans le désordre en ce qui concerne stdout et stderr.

    Attention, si ton programme retourne des centaines de milliers de lignes à l'écran (type remontage d'une sauvegarde mysql), il faut certainement adapter la gestion du TStringList.

    Cordialement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
     
     
    (*:
       DsiWin32.pas
       Collection of Win32 wrappers and helper functions.
       Free for personal and commercial use. No rights reserved.
     
       Maintainer        : gabr
       Contributors      : ales, aoven, gabr, Lee_Nover, _MeSSiah_, Miha-R, Odisej, xtreme,
                           Brdaws, Gre-Gor
       Creation date     : 2002-10-09
       Last modification : 2005-01-27
       Version           : 1.12a
    *)
     
    procedure DSiCloseHandleAndNull(var handle: THandle);
    begin
       if handle <> 0 then begin
          CloseHandle(handle);
          handle := 0;
       end;
    end; { DSiCloseHandleAndNull }
     
     
    function DSiExecuteAndCapture(const app: string; output: TStrings; const workDir: string): LongInt;
    const
       StartBufSize = 1024;
    var
       bAvail     : longword;
       bRead      : longword;
       buffer     : pointer;
       exitCode   : longword;
       iBufSize   : cardinal;
       last       : string;
       newStdIn   : THandle;
       newStdOut  : THandle;
       pBuf       : PChar;
       PI         : TProcessInformation;
       pSentinel  : PChar;
       read_StdOut: THandle;
       SA         : TSecurityAttributes;
       SD         : TSecurityDescriptor;
       SI         : STARTUPINFO;
       str        : string;
       useWorkDir : string;
       write_StdIn: THandle;
    begin
       Result := -1;
       buffer := nil;
       write_StdIn := 0;
       read_StdOut := 0;
       newStdOut := 0;
       newStdIn := 0;
       ZeroMemory(@PI, SizeOf(PI));
       ZeroMemory(@SA, SizeOf(SA));
       try
          { Za Windows NT  inicializiraj security descriptor. }
          // if DSiIsWinNT then begin
          if (Win32Platform = VER_PLATFORM_WIN32_NT) then begin
            InitializeSecurityDescriptor(@SD, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(@SD, true, nil, false);
            SA.lpSecurityDescriptor := @SD;
          end
          else
            SA.lpSecurityDescriptor := nil;
          SA.nLength := SizeOf(TSecurityAttributes);
          SA.bInheritHandle := true; // dovoli dedovanje handlov
          { Ustvari nov stdin pipe. }
          if not CreatePipe(newStdIn, write_StdIn, @SA, 0) then
            Exit;
          { Ustvari nov stout pipe. }
          if not CreatePipe(read_StdOut, newStdOut, @SA, 0) then
            Exit;
          { Nastavi parametre novega procesa. }
          ZeroMemory(@SI, SizeOf(TStartupInfo));
          SI.cb := SizeOf(TStartupInfo);
          SI.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
          SI.wShowWindow := SW_HIDE;
          SI.hStdOutput := newStdOut;
          SI.hStdError := newStdOut;
          SI.hStdInput := newStdIn;
          if workDir = '' then
            GetDir(0, useWorkDir)
          else
            useWorkDir := workDir;
          { Startaj proces. }
          if not CreateProcess(nil, PChar(app), nil, nil, true,
                   NORMAL_PRIORITY_CLASS, nil, PChar(useWorkDir), SI, PI)
          then
            Exit;
          //Result := PI.hProcess;
          last := ''; // buffer za shranjevanje nedokoncanih vrstic (brez zakljucnega CRLF)
          iBufSize := StartBufSize;
          buffer := AllocMem(iBufSize);
          try
            GetExitCodeProcess(PI.hProcess, exitCode);
            while exitCode = STILL_ACTIVE do begin
              { Poglej, ce je na stdout pipi kaj podatkov. }
              PeekNamedPipe(read_StdOut, buffer, iBufSize, @bRead, @bAvail, nil);
              if (bRead > 0) then begin
                if (iBufSize < bAvail) then begin // ce je buffer premajhen, ga povecaj
                  iBufSize := bAvail;
                  ReallocMem(buffer, iBufSize);
                end;
                ZeroMemory(buffer, iBufSize); // pocisti buffer
                ReadFile(read_StdOut, buffer^, iBufSize, bRead, nil); // preberi stdout pipe
                str := last; // shrani prejsnjo nedokoncano vrstico
                pBuf := buffer;
                pSentinel := pBuf;
                Inc(pSentinel, bRead);
                while (pBuf < pSentinel) do begin
                  case pBuf^ of
                    #0: Inc(pBuf);
                    #10:
                      begin // konec vrstice
                        Inc(pBuf);
                        Output.Add(Str);
                        str := '';
                      end; //#10
                    #13:
                      begin
                        Inc(pBuf);
                        if (pBuf < pSentinel) and (pBuf^ = #10) then
                          Inc(pBuf); // preskoci, ker je to konec vrstice
                        Output.Add(Str);
                        str := '';
                      end; //#13
                    else begin
                      str := str + pBuf^; // shrani prebrani znak
                      Inc(pBuf);
                    end; //else
                  end; //case
                end;
                last := str; // shrani morebitno nedokon?ano vrstico
              end;
              Sleep(1); // pavza
              GetExitCodeProcess(PI.hProcess, exitCode);
            end;
          finally FreeMem(buffer, iBufSize); end;
          result := exitCode ;
          if (Last <> '') then
            Output.Add(Last); // poslji zadnjo vrstico tudi, ce ni bila dokoncana
       finally
          { Pocisti za sabo. }
          DSiCloseHandleAndNull(PI.hThread);
          DSiCloseHandleAndNull(PI.hProcess);
          DSiCloseHandleAndNull(NewStdIn);
          DSiCloseHandleAndNull(NewStdOut);
          DSiCloseHandleAndNull(Read_StdOut);
          DSiCloseHandleAndNull(Write_StdIn);
       end;
    end; { DSiExecuteAndCapture }
    --
    vanquish

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    ok, je vais voir ce que je peux faire avec ça ^_^
    Merci ^_^

  8. #8
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 36
    Points : 18
    Points
    18
    Par défaut
    ça marche nickel ce truc ^_^
    Merci a toi ^_^

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 30/04/2014, 17h06
  2. Lancer un processus avec Createprocess, difficulté avec les arguments
    Par francois911 dans le forum Threads & Processus
    Réponses: 12
    Dernier message: 07/09/2011, 23h26
  3. [Batch] Lancer un batch depuis un autre avec les variables du premier
    Par mr_samy81 dans le forum Scripts/Batch
    Réponses: 3
    Dernier message: 08/04/2009, 15h40
  4. [Batch] Lancer +sieurs apps avec macro
    Par darkphenx dans le forum Windows
    Réponses: 1
    Dernier message: 16/05/2006, 08h30
  5. [batch]comment lancer un excel avec son mot de passe?
    Par victor.ward dans le forum Windows
    Réponses: 1
    Dernier message: 05/12/2005, 10h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo