PDA

View Full Version : [VB] aiuto per Shell


MisterW2
26-04-2002, 11:35
Salve,
un aiuto per l'esecuzione di programmi passati con Shell:
Il mio programma fa questo:

Private Sub Command4_Click()
Dim GoEye As String
Dim GoEye2 As String
GoEye = App.Path & "\ISO.exe """ & parpath.Text
Shell GoEye, vbNormalFocus
GoEye2 = App.Path & "\ISO.exe """ & parpath2.Text
Shell GoEye2, vbNormalFocus
End Sub

Quindi il tasto command mi attiva il programma ISO.exe 2 volte passandogli parametri diversi.
Il problema è che premendo poi il tasto partono contemporaneamente, io invece vorrei che il secondo partisse una volta terminato il primo. (senza dover sfruttare due command).
Esiste un comando opportuno?
Grazie in anticipo.

a2000
26-04-2002, 15:17
Esiste una chiamata API che puoi usare al posto di Shell allo stesso modo:

copia il codice seguente in un modulo (a parte i commenti sono 20 righe di codice).

La subroutine EseguiFOR(NomeApp) esegue l'applicazione NomeApp con eventuali parametri di comando e ne attende la conclusione (per un tempo a piacere, infinito con i set correnti).






Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF 'Wait forever
Const WAIT_OBJECT_0 = 0 'The state of the specified object is signaled
Const WAIT_TIMEOUT = &H102 'The time-out interval elapsed & the object’s state
'is nonsignaled.

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Sub EseguiFOR(NomeApp)
'Copy the following code to the command button's Click event:
' The WaitForSingleObject function returns when one of the following occurs:
' - The specified object is in the signaled state.
' - The time-out interval elapses.
'
' The dwMilliseconds parameter specifies the time-out interval, in milliseconds.
' The function returns if the interval elapses, even if the object’s state is
' nonsignaled. If dwMilliseconds is zero, the function tests the object’s state
' and returns immediately. If dwMilliseconds is INFINITE, the function’s time-out
' interval never elapses.
'
' This example waits an INFINITE amount of time for the process to end. As a
' result this process will be frozen until the shelled process terminates. The
' down side is that if the shelled process hangs, so will this one.
'
' A better approach is to wait a specific amount of time. Once the time-out
' interval expires, test the return value. If it is WAIT_TIMEOUT, the process
' is still not signaled. Then you can either wait again or continue with your
' processing.
'
' DOS Applications:
' Waiting for a DOS application is tricky because the DOS window never goes
' away when the application is done. To get around this, prefix the app that
' you are shelling to with "command.com /c".
'
' For example: lPid = Shell("command.com /c " & txtApp.Text, vbNormalFocus)
'
' To get the return code from the DOS app, see the attached text file.

Dim lPid As Long
Dim lHnd As Long
Dim lRet As Long

If Trim$(NomeApp) = "" Then Exit Sub

lPid = Shell(NomeApp, vbNormalFocus)
If lPid <> 0 Then
'Get a handle to the shelled process.
lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
'If successful, wait for the application to end and close the handle.
If lHnd <> 0 Then
lRet = WaitForSingleObject(lHnd, INFINITE)
CloseHandle (lHnd)
End If
'MsgBox "Just terminated.", vbInformation, "Shelled Application"
End If


End Sub

MisterW2
26-04-2002, 15:26
grazie mille, mi sarà sicuramente molto utile!

a2000
26-04-2002, 15:33
ti sarà o ti è ?

no perchè è la terza volta che posto questo frammento e ancora non ho capito se:


capisco male io il problema
risulta complicata la soluzione (ma non lo è ed è assolutamente quella corrente)
non capite un ca++o voi


Grazie. :p

MisterW2
26-04-2002, 15:39
Ma che dire... sicuramente io, come dici tu, non ci capisco un ca++o di VB.. dato che ci sto entrando ora...
Ho usato il futuro in quanto, enll'esempio da me fatto ripetevo il programma due volte passandogli parametri diversi, nel frattempo che nessuno mi rispondeva qui sul forum, ho ricompilato l'exe da C++ modificandolo e mettendoci sopra un main che fa il ciclo due volte con paramteri diversi.
Ho detto mi sarà perchè alla mia GUi dovrò aggiungere altri moduli sempre exe, quindi il problema si sarebbe ripetuto.

a2000
26-04-2002, 15:43
come dice Lui: "nulla ad personam"

Ciao :)


P.S.
comunque non capire un ca++o di VB non è grave, il problema è non capire un ca++o di FCA :p

MisterW2
26-04-2002, 15:56
Ti immagini.. mica mi offendo per così poco.... ;) e poi per me (come tutti i TLC) non capire un cacchio di programmazione non è un'offesa.. anzi un complimento!:D
[PS: per farti perdonare tuttavia potresti dove subire i miei post in futuro se avrò problemi...:p ]

Cmq, ho testato su un MsgBox in seguito alla Shell, ed usando quel modulo effettivamente il messaggio appare solo dopo la fine dell'esecuzione dell'exe. Non capisco dove si possa trovare difficoltà nel fare un copia-incolla....

Grazie ed alla prossima.;)

a2000
26-04-2002, 16:10
Originariamente inviato da MisterW2
[B]Ti immagini.. mica mi offendo per così poco.... ;) e poi per me (come tutti i TLC) non capire un cacchio di programmazione non è un'offesa.. anzi un complimento!:D
[PS: per farti perdonare tuttavia potresti dove subire i miei post in futuro se avrò problemi...:p ]




allora comincio io:

al volo:
meglio il samsung SGH A400 o l'eriksson T66

grazie :)

MisterW2
26-04-2002, 16:22
HEY!!:mad:
Ho detto che sono TLC (in fase di tesi...:()non un elettronico!:p
fai prima a chidere al venditore....:D

Ciap!

a2000
27-04-2002, 14:39
ah scusa ...

allora, per la propagazione, meglio pelosa o depilata ? :confused: :cool: