I want to close all running excel programs with x++

I found some code with dll but wasn’t able to make it work
#WinAPI
#DEFINE.STATUS_TIMEOUT(0x00000102)
Dll kernel32 = new Dll(“kernel32.dll”);
DllFunction createProcess = new DllFunction(kernel32, “CreateProcessA”);
DllFunction waitForSingleObject = new DllFunction(kernel32, “WaitForSingleObject”);
DllFunction closeHandle = new DllFunction(kernel32, “CloseHandle”);
DllFunction terminateProcess = new DllFunction(kernel32, “TerminateProcess”);
Binary strartupInformation = new binary(68);
Binary processInformation = new binary(16);
Someone have a solution to kill all running excel process?
I would use .NET Interop - it’s much easier to use. Take a look at GetProcessesByName() and Kill() methods of the System.Diagnostics.Process class.
Thanks again Martin,
Could you write me down a the code in x++. Because im just starting to learn ax2012, I used to work with Axapta v3.
Lets say the complete code to close all Excel open in windows tasks manager.
[:)] Thanks !
You can use something like this, but it’s up to you to adjust it as needed in your case:
System.Collections.IEnumerable processes;
System.Collections.IEnumerator enumerator;
System.Diagnostics.Process process;
try
{
processes = System.Diagnostics.Process::GetProcessesByName("EXCEL");
enumerator = processes.GetEnumerator();
while (enumerator.MoveNext())
{
process = enumerator.get_Current();
process.Kill();
}
}
catch (Exception::CLRError)
{
throw error(AifUtil::getClrErrorMessage());
}