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
public
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,
nil,
nil,
false,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo);
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',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
public
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,
nil,
nil,
false,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo);
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.