I have a couple of how-to posts on digital signatures, like this code signing post. Let me revisit this topic now that Microsoft announced some upcoming changes to code signing.
I use signtool.exe that came with Visual Studio 2013 in my examples. Here is how to use signtool.exe from the command-line to sign an executable:

FYI: in my case, I use option /a because I have more than one code signing certificate and I let signtool decide which one to use (option /a). But if you have only one code signing cert, you don’t need to use option /a.
As you can see, the version of signtool.exe I use (6.3.9600.16384) still uses sha1 by default.

To use sha256 as digest algorithm (since Microsoft will deprecate sha1), use option /fd sha256, like this:


When we look at the details of the signature, we see that there is no Signing time or Countersignatures:

The signature is valid, because we are still in the certificate validity period:

But once we are outside the certificate validity period, the signature is no longer valid:

And this is because a countersignature from a timestamping service is missing. A countersignature can be added with option /tr and the URL of a timestamping service, like this one:

Correction: use this URL for sha256 timestamping: http://timestamp.globalsign.com/?signature=sha2
Option /tr URL specifies a timestamping service that supports the RFC 3161 protocol.
And now the signature remains valid, even after the code signing certificate has expired:

To be sure that the timestamping service uses sha256, we can request this with option /td sha256:

Conclusion: always use a timestamping service when signing code, this way your signature will not expire.
Remark: code signing and timestamping are 2 different operations. There is no requirement to execute these operation with a single command. You can also timestamp a signed executable like this:

First command: sign
Second command: timestamp
And you don’t need a code signing certificate to timestamp a signed executable. You can take any executable with an embedded signature, and add a new timestamping signature with this signtool.exe timestamp command. Why do I mention this? This will become clear in a next post, where we take a closer look at Microsoft’s sha256 code signing announcement.
A last remark: as mentioned, option /a lets signtool.exe decide which certificate (from the certificate store) to use for the code signing (in case you have more than one code signing certificate). But if you want to explicitly select the code signing certificate to use, you can use option /sha1 with the sha1 fingerprint of the certificate you want to use. Important: /sha1 is a method to select a certificate, it does NOT instruct signtool to use the sha1 algorithm for the signature.