How to Execute C# code in UiPath

Using “Run Auto Hot Key” (and likely “Start Process” and “AHKActivities”, untested so far), you can run C# code from within UiPath.


Using a very slightly modified version of CLR.ahk (see here) which is included and renamed to CLR_H, you can execute C# code (or VB.Net code, but you already have an activity for that).

Try your own code! Some examples are on the website at the link to CLR.ahk above. You can place your code in the portion of ‘UiPath_CLR.ahk’ surrounded by the red rectangle in the screenshot below.
(If your class is not named “Foo”, and I doubt that it will be, be sure to also change the line:
obj := CLR_CreateObject(asm, “Foo”)
using the name of your class.


Included are ‘I_can_C_sharp.xaml’, ‘CLR_H.ahk’, and ‘UiPath_CLR.ahk’.

burque505 (3.6 KB)

p.s. Remember that ‘Run Auto Hot Key Script’ can also take arguments. If you use that activity and want a return value, you’ll need to wrap your AHK code in a function, and specify the arguments in the Properties pane of the activity.


how to use this methods?

@abdel, probably the first thing you’ll want to do is install AutoHotkey on your computer for experimenting.
You can download it from here.
I suggest also becoming familiar with AutoHotkey_H, which the provides the DLL that AutoHotkey.Interop wraps, which in UiPath can be accessed with the “Run Auto Hot Key script” activity.
To use C# in AutoHotkey, see this topic in the AHK forum.
Once you have been able to get your C# code to run, you can use “Run Auto Hot Key script” to execute your code.
I have also found LinqPad to be useful for testing code. It is much easier than firing up Visual Studio for the code I would typically run this way in UiPath.

I hope this will get you started.

i can’t found the the Run Auto Hot Key script

Hi @abdel, the UiPath.Script.Activities often are not installed when you install UiPath Studio. Please see this link for some tips on getting this and other packages. As these packages seem to vanish from the sources from time to time, I’m including an older version of UiPath.Script.Activities, which I still use, and newer version which I have not tried.


UiPath.Script.Activities.1.0.6068.29800.nupkg (560.0 KB)

UiPath.Script.Activities.1.0.6506.17442.nupkg (559.2 KB)

1 Like