Results 1 to 12 of 12

Thread: start an app

  1. #1

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179

    Cool

    how do i "shell/start" an app and not let my program continue untill the app has finished?

  2. #2
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    A few weeks ago I've had the same problem. I had found a tip on this site, I'll see if I can find it again.
    Till then.

  3. #3

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    i assume i get the application id of the program i just ran, and wait for that id to dissapear, problem is, i dont know where to start.

  4. #4
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322

    Thumbs up

    Write a separate module:

    code:

    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

    Declare Function CreateProcessA Lib "kernel32" _
    (ByVal lpApplicationName As Long, 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 Long, lpStartupInfo As _
    STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
    As Long

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

    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const INFINITE = -1&
    Private Const STARTF_USESHOWWINDOW = &H1

    Public Enum enSW
    SW_HIDE = 0
    SW_NORMAL = 1
    SW_MAXIMIZE = 3
    SW_MINIMIZE = 6
    End Enum

    Public Sub ExecCmd(cmdline$)

    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO

    'Initialize the STARTUPINFO structure:
    start.cb = Len(start)
    'start.dwFlags = STARTF_USESHOWWINDOW
    'start.wShowWindow = SW_MAXIMIZE

    'Start the shelled application:
    ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

    'Wait for the shelled application to finish:
    ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    ret& = CloseHandle(proc.hProcess)
    End Sub


    and to start your programm:

    Call ExecCmd(your_program_name)

    I couldn't find the article this fast, but I copied the code
    good luck, if you have any questions, just ask me.

  5. #5

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    thanks, i'll give it a go

  6. #6
    Member
    Join Date
    Dec 2000
    Posts
    51
    I have tried the previous code snippet and had no luck with it. I am looking for something myself

  7. #7
    TheSarlacc
    Guest

    Lightbulb How about this?

    When u start an app, it goes to the top of the Zorder! How about you obtain the apps name thru the GetWindowText API call, then run a timer every 2.5 secs or so and check if it is still running! if it is, the timer will keep goin until the app is closed. then include some code to get ur program to resume where it left off! sounds complex, it is! but i have done it be4, unfortunately i lost the code when i formatted!

  8. #8
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    Sarlacc,

    you're right about that. The problem I faced with this solutions was I had to close my form in order to make the new one appear.
    So I couln't use a timer. Another workaround for this problem was to use the system-time and make the check with that one.
    But the code I provided worked fine for me.

  9. #9

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    i have/am using the code and it is doing everything that i need it to.

    it is only being used to run some batch files.

  10. #10
    Member
    Join Date
    Dec 2000
    Posts
    51

    Question Starting an App

    I am attempting to perform an unattended install of a remote PC from a CD. I need my VB app to script all needed software installs silently and in the background. However, I have been unable to accomplish the small feat of waiting the for the shelled process to complete prior to continuing on with the next step. If anyone has any suggestions or can fix the above mentioned code snippett it would be greatly appreciated.

    Thanks

  11. #11
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    Can you describe your problem with the code I provided? Do you get an error, is the code running but doesn't perform the action requested, where does the problem appear etc. ?

  12. #12
    Member
    Join Date
    Dec 2000
    Posts
    51
    There really isn't anything to report. When I use the code A) nothing happens B) It can't create a new WOW session. I did a little research on my own and found that you need to specfiy the constant 'CREATE_SEPARATE_WOW' and adjust the security attributes. However I have been unsuccessful. It appears some the application setups that I am attempting to run are 16bit and this function wont' run them.
    Everyone!!! Can I have your attention please?

    Sit back, Relax and watch the world unfold before your very eyes.

    Mystical isn't it, oh well I tried!!!

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