Stop a Process

Started by spl, June 16, 2024, 01:51:50 PM

Previous topic - Next topic

spl

This post might generate a RFM response, but here goes:

Asked to assist with an issue based on a script I wrote using Power Query against a huge source [API REST queries]. Power Query is, itself a bit of a memory hog, but seems to settle down after the mashup provider has done it's thing. The ask centered on an issue where every once in a while after the Power Query is complete and Excel closed, trying to remove the source data [Json/csv/fabricated recordset etc..] sometimes errors with cannot delete file as it is in use by another process.

That process is: Microsoft.Mashup.Container.Loader which ends up hanging around... again this is a once in a while occurance. I have looked at the Process Extender and see the function to kill a process, but most of the examples use askitemist() to first display the processes.  I would like a UDF to perform
process = "Microsoft.Mashup.Container.Loader"
If isProcess(process) Then tKillProc(process)

the isProcess() UDF would have to have some sort of internal error handling. I see that with tOpenProc() but that wants an ID not a name. Is there a way to query by name, not PID?
Stan - formerly stanl [ex-Pundit]

td

Have you tried AppExist and AppProcID to verify the existence and retrieve a process ID?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

I originally tried appexist() with a flag of 2 [DOIT!!!]

Yes the combination of appexist() / appProcId() / tOpenProc / tKillProc is the ticket. Thanks
Stan - formerly stanl [ex-Pundit]

spl

For what it is worth, I came up with a udf and the script below has an explanation of why to use it for the particular process
;udf to terminate a nagging background app
gosub udfs
IntControl(73,1,0,0,0)

;the app below is used with Power query and normally closes when Power Query ends
;when it doesn't the user cannot delete the source app for the Power Query
;for example a large query for Jira tracker returns Jira.json file
;Power Query mcode converts the Json into formatted Excel Table
;After Power Query finishes and Excel file is saved desire is to delete Jira.json
;will fail if app below has not also closed
app = "Microsoft.Mashup.Container.Loader.exe"
if checkAndKill(app) == 0 Then Display(2,app,"Need to manually terminate with task manager.")
Exit

:WBERRORHANDLER
geterror()
Message("Error Encountered",errmsg)
Exit

:udfs
#DefineSubRoutine geterror()
   wberroradditionalinfo = wberrorarray[6]
   lasterr = wberrorarray[0]
   handlerline = wberrorarray[1]
   textstring = wberrorarray[5]
   linenumber = wberrorarray[8]
   errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
   Return(errmsg)
#EndSubRoutine

#DefineFunction checkAndKill(app)
AddExtender("WWPRC44I.DLL",0,"WWPRC64I.DLL")
If appexist(app)
   id = AppProcID(app)
   Display(2,"Terminating",app)
   canKill = tOpenProc(id,3)
   If canKill
      tKillProc(canKill)
      Display(2,"App TERMINATED",app)
   Else
      Display(2,"CANNOT TERMINATE",app)
      Return(0)
   Endif
Else
   Display(2,app,"Not Open")
Endif
Return(1)
#EndFunction

Return
Stan - formerly stanl [ex-Pundit]

td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

Quote from: td on June 18, 2024, 07:49:15 AMCool.

Appreciate that. It was actually important for the owners. The Json download is set to automate after 2am EST as the data server is PST [I gave them a time convert function]. It is then scheduled for 7am download, so the previous Jira.json needs to be removed, prior to that download, and 99% of the time it is, until the background app in question 'hangs', or whatever the new term is. As the json data is sensitive to 'issues' keeping the flow was critical.

Of course, this 'semi-automation' may cost 2 positions, and I got the 'just like what happened to you' joke, although my lay-off was for semi-automation where the business wanted to move back to manual efforts.

and a got a $50 gift certificate to CineBistro.
Stan - formerly stanl [ex-Pundit]