SignTool: how to sign a Windows app
SignTool is Microsoft's command-line tool for signing Windows executables and installers. Here's where to get signtool.exe, the exact command to sign and time stamp a file, how to verify it, and how to fix the errors you'll hit.
SignTool (signtool.exe) is the command-line tool from Microsoft that digitally signs files, verifies signatures, removes them and time stamps them. If you ship a Windows app, it's what puts your company's name on the installer in place of "Unknown publisher".
If you only want the command, here it is:
signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /a MyApp.exe
The rest of this guide explains each part, where to get the tool, and what to do when it doesn't work. The option descriptions come from Microsoft's SignTool reference.
Where to get signtool.exe
SignTool isn't a separate download. It comes with the Windows SDK, and there are three common ways to get it:
- Install the Windows SDK. Download it from Microsoft's Windows SDK page. In the installer you can untick everything except "Windows SDK Signing Tools for Desktop Apps" if SignTool is all you need.
- Install Visual Studio with a desktop development workload, which includes the SDK.
- Use the NuGet package
Microsoft.Windows.SDK.BuildTools, which is handy on build servers where you don't want a full SDK install.
After installing, the tool lives in the SDK's bin folder, under a version number and an architecture. Microsoft's example path is:
C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\signtool.exe
It isn't added to your PATH. Either open a "Developer Command Prompt for Visual Studio", where it is, or call it by its full path. To find every copy on a machine:
where /R "C:\Program Files (x86)\Windows Kits" signtool.exe
What you need before you can sign
A code signing certificate from a certificate authority. Without one you can only make a self-signed certificate, which is fine for testing and useless for customers, because their computers won't trust it.
One thing changed how this works in practice. Since June 2023, certificate authorities have to issue code signing certificates with the private key on secure hardware: a USB token, a hardware security module, or a cloud signing service. You can no longer get a new certificate as a .pfx file to copy onto a build server. That affects which SignTool options you'll use, covered below.
How to sign an exe with SignTool
With a certificate on a hardware token or in the certificate store
This is the usual case now. Plug in the token (its driver makes the certificate appear in your Windows certificate store), then:
signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /n "Your Company Name" MyApp.exe
What each option does:
| Option | What it does |
|---|---|
sign |
The command: digitally sign the file. |
/fd SHA256 |
The file digest algorithm. Required: current versions of SignTool give an error without it. Microsoft recommends SHA256. |
/tr <URL> |
The URL of an RFC 3161 time stamp server. |
/td SHA256 |
The digest algorithm for the time stamp. Required with /tr. |
/n "Name" |
Picks the certificate by its subject name. A substring is enough. |
/a |
Alternative to /n: automatically selects the best certificate. |
/sha1 <hash> |
Alternative to /n: picks the certificate by its thumbprint. The most precise option when you have several. |
/d "Description" |
A description of the signed content, shown in the UAC prompt. |
/du <URL> |
A URL with more information about the signed content. |
/v |
Verbose output. Use it whenever something fails. |
You can sign several files in one go by listing them at the end.
With a PFX file
If you have an older certificate as a .pfx file, or a self-signed one for testing:
signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /f MyCert.pfx /p YourPassword MyApp.exe
/f names the certificate file and /p gives its password. Keep that password out of your scripts and your shell history; read it from an environment variable or a secret store.
With Azure Trusted Signing
Microsoft's cloud signing service (now called Azure Artifact Signing) keeps the key in Azure, so there's no token to plug in, which makes it a good fit for CI. The guide to Azure Trusted Signing covers pricing, eligibility and setup. SignTool talks to it through a plug-in DLL:
signtool sign /v /fd SHA256 /tr http://timestamp.acs.microsoft.com /td SHA256 /dlib Azure.CodeSigning.Dlib.dll /dmdf metadata.json MyApp.exe
/dlib names the DLL that does the signing and /dmdf points to a JSON file with your account endpoint, account name and certificate profile.
Why you should always time stamp
A code signing certificate expires. If you sign without a time stamp, your signature stops being valid the day the certificate expires, and every copy of your installer already out there starts showing warnings.
A time stamp is proof from a trusted server that the file was signed while the certificate was still valid. With it, the signature stays good after the certificate expires. That's what /tr and /td are for.
Any public RFC 3161 server works. The certificate authorities run free ones, for example http://timestamp.digicert.com and http://timestamp.sectigo.com. SignTool's docs note that if time stamping fails, the command only gives a warning, so check the output: a file can come out signed but not time stamped.
There's an older /t option for a different time stamp protocol. Use /tr with /td SHA256. The two can't be combined.
How to verify a signature
signtool verify /pa /v MyApp.exe
/pa matters. Without it, SignTool checks the file against the Windows driver signing policy, and a perfectly good application signature fails. /pa uses the default authentication policy, which is the one that applies to normal apps.
Add /tw to get a warning if the signature isn't time stamped, and /all to check every signature on a file that has more than one.
You can also right-click the file in Explorer, choose Properties, and look at the Digital Signatures tab.
What to sign
- The installer (
.exeor.msi), because that's what the customer downloads and runs. - The executables and DLLs inside it, before you build the installer. Otherwise the installed app itself is unsigned.
- The uninstaller, if your installer tool generates one.
- Your update packages. An auto-updater that downloads an unsigned file is a security hole.
Most installer tools (Inno Setup, NSIS, WiX, electron-builder, Tauri's bundler) can call SignTool for you at the right points, so you configure the command once.
Signing in CI
GitHub's Windows runners come with the Windows SDK, so SignTool is already there. Since it isn't on the PATH, find it first:
- name: Sign the installer
shell: pwsh
run: |
$signtool = Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\bin" -Recurse -Filter signtool.exe |
Where-Object { $_.FullName -like "*\x64\*" } |
Sort-Object FullName -Descending | Select-Object -First 1
& $signtool.FullName sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /a dist\MyApp-Setup.exe
& $signtool.FullName verify /pa /v dist\MyApp-Setup.exe
The hard part in CI is the key, not the command, since a USB token can't be plugged into a hosted runner. The options are a cloud signing service (Azure's, or your certificate authority's own), or a self-hosted runner with the token attached.
Common SignTool errors
"SignTool Error: No certificates were found that met all the given criteria." SignTool couldn't find a usable certificate. The usual causes: the token isn't plugged in, the name after /n doesn't match the certificate's subject, the certificate has expired, the certificate is in the machine store and you didn't pass /sm, or the certificate has no private key on this computer. Run it again with /v /debug and it shows which certificates it considered and which filter ruled each one out.
"The specified timestamp server either could not be reached or returned an invalid response." The time stamp server is down, blocked by a firewall, or you used /t with a server that only speaks RFC 3161. Check the URL, use /tr, and add a retry to your build script. Time stamp servers do have bad minutes.
An error about the file digest algorithm. You left out /fd. Add /fd SHA256, and /td SHA256 next to /tr.
"'signtool' is not recognized as an internal or external command." It isn't on your PATH. Use the full path or a Developer Command Prompt.
signtool verify fails on a file you just signed. You probably left out /pa.
SignTool exits with 0 on success, 1 on failure and 2 when it finished with warnings, so a build script should treat anything other than 0 as a problem.
Signing and SmartScreen
Signing proves who published the file and that nobody changed it. It doesn't on its own make the "Windows protected your PC" screen go away. SmartScreen works on reputation: a new certificate with few downloads can still trigger the warning, and it fades as more people install your app without problems. So sign from your very first release, and keep using the same certificate so the reputation builds up in one place. An EV code signing certificate used to skip this step, and since 2024 it no longer does.
After signing: licensing and updates
A signed installer gets your app onto the customer's computer. If you sell the app, the next questions are how it knows the customer paid, and how it gets updates.
That's what LicenseSeat does: it issues a license key on each sale, your app validates it with a few lines of code, and it serves updates to licensed users. There's a C# SDK and a C++ SDK for Windows apps, and a full walkthrough in how to sell software online. It takes 0% of your revenue.
Common questions about SignTool
Where is signtool.exe located?
In the Windows SDK's bin folder, for example C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\signtool.exe. The version number in the path depends on which SDK you installed.
How do I download SignTool?
Install the Windows SDK from Microsoft. SignTool isn't offered as a standalone download. If you only want the signing tools, untick the other features in the SDK installer.
Is SignTool free?
Yes. The tool is free and comes with the Windows SDK. What costs money is the code signing certificate from a certificate authority.
Can I use SignTool without a certificate?
Only with a self-signed certificate, which is useful for testing your build script. Other people's computers won't trust it, so customers still see the "Unknown publisher" warning.
What is the difference between /t and /tr?
Both add a time stamp. /t uses an older protocol and /tr uses RFC 3161, which is the current standard and lets you choose the digest algorithm with /td. Use /tr with /td SHA256.
Does SignTool work on macOS or Linux?
No, it's a Windows program. To sign Windows executables from another system, people use open-source tools such as osslsigncode, or a cloud signing service's own client.
Do I need to sign every DLL?
It's good practice to sign every executable and DLL you ship, along with the installer. At a minimum sign the installer and your main executable.