CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: shell function

  1. #1
    Join Date
    May 2003
    Posts
    13

    shell function

    I am trying to use the shell function to call an executable. I need to allow the executable to finish before continuing processing, is there some way to do this? If I put a breakpoint in my code after the shell function the executable has time to finish and everything works fine. If I take the breakpoint out then it doesn't have time to finish and the executable doesn't work right. What can I do about this? Thanks

    ~Julian

  2. #2
    Join Date
    Feb 2001
    Location
    PA
    Posts
    163
    The following code will stop furthur code execution until the shell has completed. This example maps an O:\ drive persistently. JUst susstitue your .exe on the "ProcessID = Shell..." line.

    'Declare in module
    '**********************************************************************
    ' To run Shelled program asynchronously
    Public Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Public Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Public Const SYNCHRONIZE = &H100000
    Public Const INFINITE = &HFFFF
    '*********************************************************************


    Function NetUse(ByVal pathname As String, windowstyle As Integer) As Boolean
    ' This function is used to map everyone to the new O drive path persistently

    Dim ProcessID As Long
    Dim ProcessHandle As Long
    Dim Path As String
    Dim Map
    On Error GoTo NetUse_Error

    Map = "O: \\163.249.210.37\backup backup12 /user:makecd /PERSISTENT:YES"

    ProcessID = Shell("NET USE " & Map, 0)

    ProcessHandle = OpenProcess(SYNCHRONIZE, True, ProcessID)
    WaitForSingleObject ProcessHandle, INFINITE
    NetUse = True
    Exit Function

    ExitFunction:
    Exit Function

    NetUse_Error:
    NetUse = False
    Resume ExitFunction
    End Function

  3. #3
    Join Date
    May 2003
    Posts
    13
    thanks, that works great :-)

  4. #4
    Join Date
    Mar 2002
    Posts
    70

    Question

    Hi Julian.
    I have the same problem you had using the shell function. I got the function that Cubbie sent to you and tryed to run it but i think i dont know what are the correct sustitutions I have to do in the functions parameters.

    I am proceeding as follows:

    Shell("MY .EXE ADRESS",0)

    AS YOU CAN SEE I AM NOT USING THE MAP STRING CUBBIE USED IN THE FUNCTION.
    DO I HAVE TO USE IT?
    WHAT ARE THE CORRECT SUSTITUTIONS I HAVE TO DO IN THE MAP STRING?

    THANK'S.

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