A simple form of signing is with SignTool.exe and an Authenticode certificate (which you can buy), it could look like this:
signtool sign /f MyCert.pfx /p MyPassword /fd SHA256 MyFile.exe
See:
SignTool.exe (Sign Tool) | Microsoft Docs[
^]
and:
Everything you need to know about Authenticode Code Signing | Microsoft Docs[
^]
You don't need to do anything in code for this.
It can however be difficult to find the location of SignTool.exe, as it seems to change with every new Windows version.
Most of the time it can be found in:
C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe
Another option if you don't want to buy a certificate is:
Creating Self-signed Certificates[
^]