Announcement

Collapse
No announcement yet.

Getting Nuts About This

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

  • Getting Nuts About This

    Hi Guys,

    Running a proggie with OpenProcess works ok but...

    Second time it pops up the proggie tryed everything Send wm_close etc
    Still second time it pops up no matter what.

    And when i do run this same proggie for hundred times from a batch job it work ok ?

    Hope someone know a solution
    To Ask or Not To Ask ?

  • #2
    I think you are a tad short on specifics, but....

    The "OpenProcess" Windows' API function does not execute ("run?") a program [file].

    Strangely enough, it opens a existing process.

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      tad short on specifics
      "Tad"?? What "Tad"???...."I don't see Tad"??? (sorry bad spin from a quote from "Short Circuit")

      I do not even see a reference to any details what so ever....

      Adrian, I gotta ask the following: (short of pulling a "Johnny Carson - The Great Karnak")
      1. What program / process
      2. Is this program / process already running? or Run when you "OpenProcess"?
      3. Code used to open this program / process?
      4. Do you mean that the 1st time it runs (not seen) but the 2nd it is seen? but the 3rd and so on times not seen?


      Sorry if it sounded mean or rude, but I am totally :confused2: over what the question is, and what it is that you are even attempting to do?
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        Sorry Guys,

        A bit short maybe, but finally found it, was not the proggie, it was in a wrong string that made it popup.

        MM OpenProcess start proggies perfect, I found some code here and made it into a Func.



        Code:
        #COMPILE EXE
        #DIM ALL
        #INCLUDE "Win32Api.inc"
        
        DECLARE FUNCTION AvStartProg(Run AS STRING) AS DWORD
        
        
        FUNCTION PBMAIN () AS LONG
        
        LOCAL ExitCode AS DWORD
          
          Exitcode=AvstartProg("Calc.exe")
          MSGBOX "EXitCode :" + STR$(ExitCode)
        
          Exitcode=AvstartProg("M:\Test\LogiUsbMouse.exe")
          MSGBOX "EXitCode :" + STR$(ExitCode)
        
          Exitcode=AvstartProg("M:\Test\TrueCrypt.exe")
          MSGBOX "EXitCode :" + STR$(ExitCode)
        
          ' Start all without a problem
        
        END FUNCTION
        
        FUNCTION AvStartProg(Run AS STRING) AS DWORD
               LOCAL ProcID AS DWORD, ProcHandle AS DWORD, ExitCode AS DWORD
               ProcID=SHELL (Run)
               ProcHandle = OpenProcess(%PROCESS_QUERY_INFORMATION, BYVAL 0, ProcID)
               DO
                  GetExitCodeProcess ProcHandle, ExitCode
                  SLEEP 5
               LOOP UNTIL (ExitCode <> %STILL_ACTIVE)
               CloseHandle ProcHandle
               FUNCTION=ExitCode
        END FUNCTION
        Credits To Peter Lamelijn If I Remember Ok I got it from his code
        To Ask or Not To Ask ?

        Comment


        • #5
          >MM OpenProcess start proggies perfect

          Um, no it doesn't. In your program, SHELL is executing the program file; OpenProcess is opening the process so you can query the status.

          Since I hate 'looping' instead of 'waiting', here is some code to do that
          Code:
          FUNCTION AvStartProg(Run AS STRING) AS DWORD
                 LOCAL ProcID AS DWORD, ProcHandle AS DWORD, ExitCode AS DWORD
                 ProcID   =SHELL (Run)
                 ProcHandle = OpenProcess(%PROCESS_QUERY_INFORMATION, BYVAL 0, ProcID)
                 iwait = WaitForSingleObject (ProcHandle, %INFINITE)
                 IF iWait = %WAIT_OBJECT_0 THEN 
                          GetExitCodeProcess ProcHandle, ExitCode
                ELSE
                    (set return code meaning WFSO failed) 
                END IF
                 CloseHandle ProcHandle
                 FUNCTION=ExitCode
          END FUNCTION
          Not included: testing that both SHELL and OpenProcess are in fact succeeding before waiting for the process to complete.
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Yep MM,

            Your right, BTW i was looking at WaitForSingleObject but was not sure if it could do the trick, so thanks Michael, I will study this function some more from your example.


            He he stupid from me also, just to busy last weeks with to many different program languages, but I now finally decided to drop Vis Stud, getting sick of all this over bloated stuff manuals that send you from wall to the closet and back again spend more time on reading than coding and if you code it is as slow as hell so done with it for good now. Getting more and more happy with PowerBasic and regret I did not drop the other stuff 3 years ago.
            To Ask or Not To Ask ?

            Comment


            • #7
              Hmmmmm Adrian, it sounds like my thoughts a bit back.
              The only Visual Studio garbage I do these days is basic examples how to use my dll in in Visual Studio, and other so called languages like Labview.

              PB gives me all the power, and none of the bloat (unless I ask for it )
              And even goes to the more extreme if I need to go hardcore....assembly is available too......now THAT is a BARGAIN

              (Just out of "Morbid Curiosity"....since you have messed with Visual Studio, you wouldn't happen to know how to pass a C++ "HANDLE" to a number that my DLL could use do you?.....like I said "Morbid Curiosity" )
              Engineer's Motto: If it aint broke take it apart and fix it

              "If at 1st you don't succeed... call it version 1.0"

              "Half of Programming is coding"....."The other 90% is DEBUGGING"

              "Document my code????" .... "WHYYY??? do you think they call it CODE? "

              Comment


              • #8
                Sorry Cliff

                I don't but probably Edwin Knoppert can help you with you that i did mostly VB.Net.
                Asm was my old days language, Cliff used to make lib's for other programmers, did already some small stuff again in PB and got a few samples from this forum , so will pick it up again also.

                Problem with us guys is we are not used to a jail where you proggie must live in, with rules how you must code etc. Not a easy decision to make anyway, but I figured PB and Win with API will be long enough around. And stupid maybe but this community has something too do with my decision also Cliff , if your stuck at least your not alone but have a bunch off guys hanging out to help.
                To Ask or Not To Ask ?

                Comment


                • #9
                  Here's a demo of using ShellExectuteEx plus WFSO to replace SHELL under multiple conditions:
                  Win 32: Monitor Process with ShellExecuteEx June 22, 2001

                  That demo is not just old, it was developed under Windows/98; so I'd double check the MS-DOS stuff.
                  Michael Mattias
                  Tal Systems Inc. (retired)
                  Racine WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X