CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2000
    Location
    Israel,tel-aviv
    Posts
    25

    How can I see that the program (executed by SHELL Func') completed?

    Hi,
    I use Shell function to run a batch file that get some arguments, Then the Batch file write a log file, which I read and analyze. The problem is that i need to automatically analyze it as soon as the batch file completed it task.But, I dont now how to know whether the batch file has completed to run. do you know how?

    Shell path_lcl_drive.Text & Scc_Batch_File & " " & _
    sccipadrs.Text & " " & win_ver.Text & " " & setup_ver.Text & _
    " " & scc_dir_updt_virtex.Text & " " & src_sub_dir_virtex.Text & " " & path_cptn.Text & " " & path_lcl_drive.Text, vbMaximizedFocus



    Eli

  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: How can I see that the program (executed by SHELL Func') completed?

    check http://vblib.virtualave.net, there is a function called RunAppWait in vbSystem of the activeX DLL which will run a program and wait until it finish.



    HTH

    cksiow
    http://vblib.virtualave.net - share our codes

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How can I see that the program (executed by SHELL Func') completed?


    'one form (name = Fwait)
    'one commandButton (=Command1)
    option Explicit

    Const INFINITE = -1&

    private Declare Function WaitForSingleObject Lib "kernel32" (byval hHandle as Long, byval dwMilliseconds as Long) as Long
    private Declare Function OpenProcess Lib "kernel32" (byval dwDesiredAccess as Long, byval bInheritHandle as Long, byval dwProcessId as Long) as Long

    private Function Chiama_E_Attendi(sFile as string) as Long
    Dim lngExecOK as Long
    Dim lProcessHandle as Long
    Dim lReturnValue as Long

    on error GoTo errHandler
    If Dir(sFile) <> "" then
    me.Hide 'hide this form, to see it come back when process ends
    lngExecOK = Shell(sFile, vbNormalFocus)

    'handle to process
    lProcessHandle = OpenProcess(&H100000, true, lngExecOK)

    'Wait
    lReturnValue = WaitForSingleObject(lProcessHandle, INFINITE)


    me.Show 'showme again

    'MsgBox "Ended execution " & Now

    Chiama_E_Attendi = lReturnValue
    else
    MsgBox "file not found"
    End If
    Exit Function

    errHandler:
    MsgBox Err & Space(2) & error$
    Err.Clear
    Unload me
    set FWait = nothing
    End Function

    private Sub Command1_Click()
    Dim ret
    ret = Chiama_E_Attendi("c:\windows\notepad.exe")
    End Sub





    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Whoops...

    A batch file? you mean it has no window? Well, I am afraid my code will not work...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Apr 2000
    Posts
    737

    Re: Whoops...

    it will if he run some dos program, as it will bring up a dos prompt window, just remember to check on the close on exit for the property page.

    HTH

    cksiow
    http://vblib.virtualave.net - share our codes

  6. #6
    Join Date
    May 2001
    Location
    India, Bangalore
    Posts
    14

    Re: How can I see that the program (executed by SHELL Func') completed?

    Check the return value of the Shell()if it returns 0 then Shell() has not executed correctly otherwise Shell() has executed correctly. I think this code snippet may help you..

    Dim RetVal
    RetVal = Shell("C:\Test.bat", 1)
    if RetVal=0 then
    msgbox "Failure"
    else
    msgbox "Success"
    end if


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured