Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To run a small VBappl. in the background... Please, Urgent

Status
Not open for further replies.

bzac

Programmer
Dec 20, 2000
55
US
Have to run an updation program in the background, when the user hits "Apply". Here the user could be able to enter the next data without waiting till the updation complete.
Here I am using :

Dim Retval
Retval = Shell"c:\zacdfs\back\backexe\backdemandexe.exe", vbNormalNoFocus) ' , 6)


here I am not getting the control back to my entry form until this task completed.

Is it possible to make a que, if the last instance of the shelled program not yet completed execution when the next instance comes up ?

Can I run a program residing in the Server through the programe in the client side ?


I am sure somebody can help me, please, urgent.
 
I created a class called CExec.cls and used this code in it. Just replace the Shell command in your code with ExecCmd. Be sure to create the object like this:

Dim objExec as CExec

Set objExec = New CExec
objExec.ExecCmd "c:\zacdfs\back\backexe\backdemandexe.exe"
Set objExec = Nothing
Code:
Option Explicit
'See Q129796 in the Knowledge Base for further details of this.
'[URL unfurl="true"]http://support.microsoft.com/support/kb/articles/q129/7/96.asp[/URL]
'
'Code was taken from the MSDN site.

Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
    hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
    lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
    lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
    lpStartupInfo As STARTUPINFO, lpProcessInformation As _
    PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" _
    (ByVal hObject As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
    (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const NORMAL_PRIORITY_CLASS As Long = &H20
Private Const INFINITE  As Long = -1

Public Function ExecCmd(strCommandLine As String)
    Dim lngReturn As Long
    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO

    ' Initialize the STARTUPINFO structure:
    start.cb = Len(start)

    ' Start the shelled application:
    lngReturn = CreateProcessA(vbNullString, strCommandLine, 0&, 0&, 1&, _
            NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

    ' Wait for the shelled application to finish:
    lngReturn = WaitForSingleObject(proc.hProcess, INFINITE)
    Call GetExitCodeProcess(proc.hProcess, lngReturn)
    Call CloseHandle(proc.hThread)
    Call CloseHandle(proc.hProcess)
    ExecCmd = lngReturn
End Function
Snaggs
tribesaddict@swbell.net
There are two kinds of people in life: people who like their jobs, and people who don't work here anymore.
 
Thank you very much snaggs, I will try with it and let you know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top