1. Dave O'BILOG
  2. PowerBuilder
  3. Monday, 18 February 2019 14:58 PM UTC

Hi,

it's possible to close an external application with Powerbuilder ?

example : close 'xxxx.exe' ?

thanx

Accepted Answer
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Monday, 18 February 2019 15:27 PM UTC
  2. PowerBuilder
  3. # Permalink

You can do this though a windows API call.

Look at this thread:

https://www.experts-exchange.com/questions/20450104/Stop-an-external-application-from-PowerBuilder.html

You might find a solution to your problem.

Cheers David

Comment
There are no comments made yet.
CJ Lai Accepted Answer Pending Moderation
  1. Wednesday, 26 February 2020 19:58 PM UTC
  2. PowerBuilder
  3. # 1

The VB script in this post works for me

https://bit.ly/32tCYrb

Comment
There are no comments made yet.
Daniel Vivier Accepted Answer Pending Moderation
  1. Friday, 1 March 2019 22:18 PM UTC
  2. PowerBuilder
  3. # 2

I just wrote a C function to do that (stolen from some other support thread). It seems to be working fine.

/* Try to kill a process with a given filename (e.g. foo.exe), that is not your current process!
* Return 1 if it was killed, -1 if it was found but could not be killed, 0 if it was not found.
*/
__declspec(dllexport) LONG32 __stdcall killProcessByName(const char *filename)
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
DWORD myProcessID;
int ret = 0;

pEntry.dwSize = sizeof(pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);

myProcessID = GetCurrentProcessId();

while (hRes)
{
if (stricmp(pEntry.szExeFile, filename) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,
(DWORD)pEntry.th32ProcessID);
if (hProcess != NULL)
{
if (pEntry.th32ProcessID != myProcessID)
{
if (TerminateProcess(hProcess, 9))
ret = 1;
else
ret = -1;
}
CloseHandle(hProcess);
if (ret != 0) break;
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
return ret;
}

I declare that in PB (given that I am compiling as ANSI) as:

function long KillProcessByName(String filename) library "mylib.dll" alias for "killProcessByName;ansi"

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.