Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-01-2009
Charly911 Charly911 is offline
Miembro
 
Registrado: ene 2009
Ubicación: Bs As, Argentina
Posts: 11
Poder: 0
Charly911 Va por buen camino
Cool Ejecutar scripts .vbs -> Solucionado

Hola gente del foro, primero que nada me quiero presentar.
Soy Cristian, 19 años, Argentino, primer post
De programacion se poco, y lo que se lo aprendi por mi cuenta leyendo, copiando, probando....

Estoy haciendo un pequeño programa que ejecuta scripts de visual basic para instalar programas. Es una lista con CheckBox que revisa una por una y ejecuta un script a la vez, y espera a que termine el instalador para ejecutar el siguiente. El programa esta casi listo, ya que lo probe con ejecutables y funciono a la perfeccion. Pero luego lo probe con los scripts y no anda
Para la ejecucion use la funcion CreateProcess, ya que con esta puedo verificar si el proceso esta o no en ejecucion.

Codigo:

Código Delphi [-]
unit PostSateging;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, jpeg, ExtCtrls, SHELLAPI;

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    Button1: TButton;
    CheckBox12: TCheckBox;
    procedure Button1Click(Sender: TObject);
          private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Form2: TForm2;

implementation

{$R *.dfm}


 function WinExecAndWait32(FileName:String; Visibility:integer):integer; //Esta funcion la copie de la web...
 var
   zAppName:array[0..512] of char;
   zCurDir:array[0..255] of char;
   WorkDir:String;
   StartupInfo:TStartupInfo;
   ProcessInfo:TProcessInformation;
   Resultado,exitCode: DWord;
 begin
   StrPCopy(zAppName,FileName);
   GetDir(0,WorkDir);
   StrPCopy(zCurDir,WorkDir);
   FillChar(StartupInfo,Sizeof(StartupInfo),#0);
   StartupInfo.cb := Sizeof(StartupInfo);

   StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow := Visibility;
   CreateProcess(nil,
     zAppName,                      { pointer to command line string }
     nil,                           { pointer to process security attributes}
     nil,                           { pointer to thread security attributes}
     false,                         { handle inheritance flag }
     CREATE_NEW_CONSOLE or          { creation flags }
     NORMAL_PRIORITY_CLASS,
     nil,                           { pointer to new environment block }
     nil,                           { pointer to current directory name }
     StartupInfo,                   { pointer to STARTUPINFO }
     ProcessInfo);

   {Espera a que termine la ejecucion}
   {Wait until execution finish}
   Repeat
     exitCode := WaitForSingleObject( ProcessInfo.hProcess,1000);
     Application.ProcessMessages;
   Until (exitCode <> WAIT_TIMEOUT);
   GetExitCodeProcess(ProcessInfo.hProcess,Resultado);
   MessageBeep(0);
   CloseHandle(ProcessInfo.hProcess );
   Result:=Resultado;
 end;


procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckBox1.Checked then WinExecAndWait32('C:\Documents and Settings\Charly\Escritorio\hola.vbs'{C:\Packages\ACCSS002003ENGC1\ACCSS002003ENGC1-JM.vbs'},1);
if CheckBox2.Checked then WinExecAndWait32('C:\Packages\OLPCA601312ENGC1\OLPCA601312ENGC1.vbs',1);
if CheckBox3.Checked then WinExecAndWait32('C:\Packages\Citrix 10.1\ica32pkg.vbs',1);
if CheckBox4.Checked then WinExecAndWait32('C:\Packages\install_flash_player\install_flash_player.vbs',1);
if CheckBox5.Checked then WinExecAndWait32('C:\Packages\ORACL000817ENGC1\ORACL000817ENGC1_VE_dep.vbs',1);
if CheckBox6.Checked then WinExecAndWait32('C:\Packages\DVLPR000045ENGC2\DVLPR000045ENGC2_VE_dep.vbs',1);
if CheckBox7.Checked then WinExecAndWait32('C:\Packages\PDFCT000093ENGC1\PDFCT000093ENGC1_deploy.vbs',1);
if CheckBox8.Checked then WinExecAndWait32('C:\Packages\PRJCT002003ENGC1P1\PRJCT002003ENGC1P1_deploy.vbs',1);
if CheckBox9.Checked then WinExecAndWait32('C:\Packages\SAPGU000640ENGC3\SAPGU00064ENGC3_VE_dep.vbs',1);
if CheckBox10.Checked then WinExecAndWait32('C:\Packages\SISLG000010SPAC1\SISLG000010SPAC1_deploy.vbs',1);
if CheckBox11.Checked then WinExecAndWait32('C:\Packages\Scripts\CONF_LOC.vbs',1);
if CheckBox12.Checked then WinExecAndWait32('C:\Packages\Scripts\RestartSystem.vbs',1);
end;

end.
Les agradeceria que me indiquen si es posible ejecutar este tipo de archivos con esta funcion, o si hay otra que me sirva.

Cristian.

-----------------------------------

Edit ->

Como la funcion CreateProcess solo puede ejecutar archivos .exe lo que hay que hacer para ejecutar cualquier archivo, en este caso un .vbs, se debe ejecutar el programa que lo abre diciendole que abra el archivo.
El codigo quedaria asi:

Código Delphi [-]
unit PostSateging;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, jpeg, ExtCtrls, SHELLAPI;

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    Button1: TButton;
    CheckBox12: TCheckBox;
    procedure Button1Click(Sender: TObject);
          private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Form2: TForm2;

implementation

{$R *.dfm}


 function WinExecAndWait32(FileName:String; Visibility:integer):integer;
 var
   zAppName:array[0..512] of char;
   zCurDir:array[0..255] of char;
   WorkDir:String;
   StartupInfo:TStartupInfo;
   ProcessInfo:TProcessInformation;
   Resultado,exitCode: DWord;
 begin
   StrPCopy(zAppName,FileName);
   GetDir(0,WorkDir);
   StrPCopy(zCurDir,WorkDir);
   FillChar(StartupInfo,Sizeof(StartupInfo),#0);
   StartupInfo.cb := Sizeof(StartupInfo);

   StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow := Visibility;
   CreateProcess(nil,
     zAppName,                      { pointer to command line string }
     nil,                           { pointer to process security attributes}
     nil,                           { pointer to thread security attributes}
     false,                         { handle inheritance flag }
     CREATE_NEW_CONSOLE or          { creation flags }
     NORMAL_PRIORITY_CLASS,
     nil,                           { pointer to new environment block }
     nil,                           { pointer to current directory name }
     StartupInfo,                   { pointer to STARTUPINFO }
     ProcessInfo);

   {Espera a que termine la ejecucion}
   {Wait until execution finish}
   Repeat
     exitCode := WaitForSingleObject( ProcessInfo.hProcess,1000);
     Application.ProcessMessages;
   Until (exitCode <> WAIT_TIMEOUT);
   GetExitCodeProcess(ProcessInfo.hProcess,Resultado);
   MessageBeep(0);
   CloseHandle(ProcessInfo.hProcess );
   Result:=Resultado;
 end;


procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckBox1.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\ACCSS002003ENGC1\ACCSS002003ENGC1-JM.vbs',1);
if CheckBox2.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\OLPCA601312ENGC1\OLPCA601312ENGC1.vbs',1);
if CheckBox3.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\Citrix 10.1\ica32pkg.vbs',1);
if CheckBox4.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\install_flash_player\install_flash_player.vbs',1);
if CheckBox5.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\ORACL000817ENGC1\ORACL000817ENGC1_VE_dep.vbs',1);
if CheckBox6.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\DVLPR000045ENGC2\DVLPR000045ENGC2_VE_dep.vbs',1);
if CheckBox7.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\PDFCT000093ENGC1\PDFCT000093ENGC1_deploy.vbs',1);
if CheckBox8.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\PRJCT002003ENGC1P1\PRJCT002003ENGC1P1_deploy.vbs',1);
if CheckBox9.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\SAPGU000640ENGC3\SAPGU00064ENGC3_VE_dep.vbs',1);
if CheckBox10.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\SISLG000010SPAC1\SISLG000010SPAC1_deploy.vbs',1);
if CheckBox11.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\Scripts\CONF_LOC.vbs',1);
if CheckBox12.Checked then WinExecAndWait32('C:\WINDOWS\system32\wscript.exe C:\Packages\Scripts\RestartSystem.vbs',1);
end;

end.

Cristian.

Última edición por Charly911 fecha: 12-01-2009 a las 13:15:05.
Responder Con Cita
 



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
Generacion de scripts AMO Oracle 2 10-10-2005 17:55:15
Ejecutar automaticamente scripts en tiempo de ejecucion meosre MySQL 1 30-09-2005 06:42:25
Scripts? JMGR Varios 2 14-06-2005 21:03:49
Componente para ejecutar scripts gendelphi Firebird e Interbase 1 02-09-2004 20:15:46
scripts en phpmyadmin __cadetill PHP 39 22-04-2004 00:10:20


La franja horaria es GMT +2. Ahora son las 13:15:33.


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