Announcement

Collapse
No announcement yet.

How do I close a SHELLed program programatically?

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

  • How do I close a SHELLed program programatically?

    I don't have any problem starting an app with the SHELL function, but how does one go about closing the program programmatically? This is a process that does not have its own window. I've searched, but must be using the wrong search terms, or else there isn't anything in this fabulous resource that meets my needs. It may be that I'm complicating something when I don't have to, so a nudge in the right direction would be appreciated.
    Rod
    "To every unsung hero in the universe
    To those who roam the skies and those who roam the earth
    To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

  • #2
    Maybe something like this..?
    Code:
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
    '------------------/
    
    Function PBMain () As Long
     Local shellid As Dword
    
     shellid = SHELL ("Notepad.exe",6)
     ' ... background tasks etc
    
     Sleep 6000 : WinBeep 400, 500     ' enough already !
      ' TerminateProcess
      Local hShellProcess As Dword
       hShellProcess = OpenProcess(%PROCESS_TERMINATE, %FALSE, shellid)
       TerminateProcess(hShellProcess, 0)
       CloseHandle(hShellProcess)
    
    End Function
    '------------------/PBMain
    Rgds, Dave

    Comment


    • #3
      Like a charm!! Thanks Dave!!
      Rod
      "To every unsung hero in the universe
      To those who roam the skies and those who roam the earth
      To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

      Comment


      • #4
        It makes a great MACRO...
        Code:
        MACRO End_SHELL (pid1)
          MACROTEMP hShellProcess
          LOCAL hShellProcess AS DWORD
          hShellProcess = OpenProcess(%PROCESS_TERMINATE, %FALSE, pid1)
          TerminateProcess(hShellProcess, 0)
          CloseHandle(hShellProcess)
        END MACRO
        Thanks again!!
        Rod
        "To every unsung hero in the universe
        To those who roam the skies and those who roam the earth
        To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

        Comment


        • #5
          That works great to kill a process on the same machine in its tracks.

          If the shelled to program is on another machine it might be better to open a shared file
          and just close it on the sheller to tell the shelled to program to end. Other ways might
          include setting a byte in a shared file or checking for the existence of a file.
          Killing another process could have side-effects depending upon the program.

          https://duckduckgo.com instead of google

          Comment


          • #6
            That works great to kill a process on the same machine in its tracks.
            That is the desired result for the program I have in mind and it shouldn't have dire consequences. But I will monitor its usage as things develop as some things grow beyond the original intent. Thanks!
            Rod
            "To every unsung hero in the universe
            To those who roam the skies and those who roam the earth
            To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

            Comment

            Working...
            X