Run external exe from kinetic client not working

We’re trying to launch an exe on a button click in kinetic (client, not web). It works in our old classic customization, but that was written in vb. I have the code in a function that runs on button click, and I was trying to run notepad just to get any exe working, but nothing happens. I can confirm that the function is being called and the filepath is correct. Code below. Any ideas?

var process = new System.Diagnostics.Process();
  
process.StartInfo.FileName = @"notepad.exe";
process.StartInfo.WorkingDirectory = @"C:\Windows\system32\";

process.Start();

This worked for me on 2022.2:

	private void epiButtonC1_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		// Prepare the process to run
		var process = new System.Diagnostics.Process();
		ProcessStartInfo start = new ProcessStartInfo();
		start.FileName = @"notepad.exe";
		process.StartInfo.WorkingDirectory = @"C:\Windows\system32\";
		int exitCode;
		
		using (Process proc = Process.Start(start))
		{
		     proc.WaitForExit();
		
		     // Retrieve the app's exit code
		     exitCode = proc.ExitCode;
		}
	}
1 Like

Thanks for the quick reply.
I tried copying your code, but it just runs forever without opening notepad.
I’m writing the function in Epicor Functions Maintenance and calling it with the erp-function widget in application studio on button click.

That’s trying to run notepad on the server.

2 Likes

Thanks!
Is it possible to do it locally? And if so do you know how?

Yes, with restrictions. You will have to register a custom url handler on the workstation.
To “launch” the app, you will provide a link, that the handler will open.

Based on your original post, it sounds like you had the code in the UI since you mentioned VB.
To do it locally, you could still do it in the UI with the code I gave.
I’m going to postulate that you’re moving to to a function to be reused without copying code around to each screen? Or is there another reason you’re moving it to a function?

1 Like

I wasn’t aware of another way to execute code (from user-interaction like a button click) in the kinetic style screens other than to put it in a function (from Epicor Functions Maintenance). The VB was from our old customizations in E10 that were all on classic-style screens that we’re trying to convert to kinetic-style now that we’ve upgraded to E11.

Ah, okay–that makes sense.
So, as far as I know there’s no way to do this in a friendly way in App Studio.
There’s a pretty big security risk if a web browser application would allow an executable to launch on the client machine.

I’ll defer to @klincecum since I don’t know anything about custom URL handlers.
Whenever you get that set up, there’s a url-open widget that can launch URLs.

1 Like

That should probably do the trick after the url handler is set up.
I haven’t messed with it in a while, but I’ll see if I can find some relevant and
modern documentation.

I Agree Yes Yes Yes GIF by Tracey Matney - Victory Points Social

1 Like

Let’s rewind, cause doing this in the browser is a terrible idea. What is the original problem you are trying to solve?

What did the original customization do and why?

It opened Notepad. Have you not been following along :rofl:

However this statement:
“I’m writing the function in Epicor Functions Maintenance and calling it with the erp-function widget in application studio on button click.”

Does not support this statement:
“in kinetic (client, not web).”

We had created what amounted to external “epicor” screens (basically winforms exes or similar), which supplemented the functionality of epicor. By having these open from our customization, it made it easier to run them for our users, and then the screen could also close when epicor closes (instead of users having to close them all manually).

What makes them special enough to warrant an external application instead of customizing a UD Table and screen within Epicor?

2 Likes

Yeah this sounds like you need custom screens in Epicor which can all 100% be done with app studio and or classic customization

And if the functionality MUST be in an external app, can you convert those programs to web apps (using Web Forms maybe)? This would make it easier to integrate with Kinetic UI. It would make deployments much, much easier as well.

1 Like

Thanks everyone, we’ll look at either converting these to a custom epicor screen or a web app.

2 Likes

If you want to do it:

Sample reg file for an url handler on windows:

KittensUrlHandler.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\kittens]
@="URL:Kittens Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\kittens\DefaultIcon]
@="notepad.exe,1"

[HKEY_CLASSES_ROOT\kittens\shell]

[HKEY_CLASSES_ROOT\kittens\shell\open]

[HKEY_CLASSES_ROOT\kittens\shell\open\command]
@="powershell.exe -File C:\\Users\\klincecum\\Desktop\\kittensParser.ps1 \"%1\""

Sample parser for url handler data received:

kittensParser.ps1

# You will receive the complete text from your custom url handler:
# "kittens:c:\users\klincecum\desktop\arecute.txt"
#
# The text you will receive from the url handeler will be mangled:
# "kittens:c:%5Cusers%5Cklincecum%5Cdesktop%5Carecute.txt" instead of
#
# I used powershell to give you a start on a simple argument processor:

# Lets Launch notepad
$executablePath = "notepad.exe"

# Replace "kittens:" from our %1 argument variable passed from the custom url handler
$parsedArgs = $args[0].replace('kittens:','')

# Replace "%5C" with "\"
$parsedArgs = $parsedArgs.replace('%5C','\')

$quote = '"'

# Build our command, and wrap in quotes ( notepad.exe "c:\users\klincecum\desktop\arecute.txt" )
$output = $executablePath + ' ' + $quote + $parsedArgs + $quote

# Launch command
Invoke-Expression $output


#Debugging Stuff
#Add-Type -AssemblyName PresentationFramework
#[System.Windows.MessageBox]::Show($output)
#Write-Host $output
#Pause

arecute.txt

Oh Yes They are!



KittensNotepad

lol, what’s the :face_vomiting: for @hmwillett ?