Announcement

Collapse
No announcement yet.

Starting/Controll a shell process..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Starting/Controll a shell process..

    I am aware of how to start a shell in VB and use the CreatProcessA
    command to determine when a shell is comple. Could someone
    explain in more detail the STARTUPINFO type and how to start
    a process "Minimized"?

    I noticed there is a wShowWindow variable within this type but without
    an explanation of the type structure and its uses, I am kinda
    lost...



    ------------------
    Explorations v3.0 RPG Development System
    http://www.explore-rpg.com
    Explorations v9.10 RPG Development System
    http://www.explore-rpg.com

    #2
    In my opinion, MSDN explains this very clear. But anyway

    Code:
         #Compile Exe
         #Dim All
         #Register None
         #Include "WIN32API.INC"
    
         $CmdLine = "notepad.exe"
    
         Function PbMain
             Dim PI As PROCESS_INFORMATION
             Dim SI As STARTUPINFO
    
             SI.cb = SizeOf(SI)
             SI.dwFlags = %STARTF_USESHOWWINDOW
             SI.wShowWindow = %SW_MINIMIZE
    
             MsgBox "Minimized. Click Ok and see taskbar"
             
             CreateProcess ByVal 0&, $cmdline, ByVal 0&, ByVal 0&, ByVal 1&, _
               %NORMAL_PRIORITY_CLASS, ByVal 0&, ByVal 0&, SI, PI
             If PI.hProcess Then WaitForSingleObject PI.hProcess, %INFINITE: _
                CloseHandle PI.hProcess
                
             SI.wShowWindow = %SW_MAXIMIZE
    
             MsgBox "Maximized"
    
             CreateProcess ByVal 0&, $cmdline, ByVal 0&, ByVal 0&, ByVal 1&, _
               %NORMAL_PRIORITY_CLASS, ByVal 0&, ByVal 0&, SI, PI
             If PI.hProcess Then WaitForSingleObject PI.hProcess, %INFINITE: _
                CloseHandle PI.hProcess
             
             MsgBox "Finished"
    
       End Function
    ------------------
    E-MAIL: [email protected]

    Comment


      #3
      The PB SHELL function & statement have a style parameter.
      Use 2 or 6 for minimized (or 0 for hidden).



      ------------------
      Bernard Ertl
      Bernard Ertl
      InterPlan Systems

      Comment


        #4
        If you use CreateProcess, don't forget to CloseHandle PI.hThread also.

        ------------------
        Tom Hanlin
        PowerBASIC Staff

        Comment


          #5
          Tom --
          CloseHandle PI.hThread returns non-zero and it looks that it's necessary to do it.
          But I am curious, what happends, if do not CloseHandle finished process/thread.
          Memory leaks only or something worse ?


          ------------------
          E-MAIL: [email protected]

          Comment


            #6
            Nothing worse than a leak, as far as I know. But, no value in leaking!

            ------------------
            Tom Hanlin
            PowerBASIC Staff

            Comment


              #7
              Do you close the thread before the process or after?


              ------------------
              ATB

              Charles Kincaid

              Comment


                #8
                You can close the process and/or thread handles as soon as you don't need them any more.
                If you don't use them, you can close them immediately when CreateProcess returns.


                ------------------
                Tom Hanlin
                PowerBASIC Staff

                Comment

                Working...
                X
                😀
                🥰
                🤢
                😎
                😡
                👍
                👎