When was the last time you decided you needed to deploy a product of yours. How often is it that you run into a situation where configuration and the manual to installation of your projects becomes a royal pain in the neck? Well, for most, maybe not all that often, but for the few in the corporate world - this may happen all too often.
It's nice having ClickOnce features to do a lot of the work for us. But unfortunately ClickOnce can't handle all the nitty gritty components we would like it to.
Tool Number 1: Automated Installation of Certificates into the Certificate Store
You can use the CertMgr.exe to automate the use of importing certificates into a certificate store. The CertMgr comes with the .NET Framework SDK Tools and is typically located in %ProgramFiles% \Microsoft SDKs\ Windows\ v6.0A\bin\certmgr.exe. Executing the following will import a certificate into the localmachine personal certificate store.
certmgr /add MyCertificate.pfx /r LocalMachine /s My -all
certmgr /del /n "My CertSubject Name" /r LocalMachine /s My -c
This makes it especially useful when you are working with services that require use of certificates. Believe it's a pain :/
Unfortunately, this method will not work for certificates that are password protected. For that, you can write up a little C# program that will take care of those password protected situations.
using System;
using System.Security.Cryptography.X509Certificates;
namespace AddCert
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 7 && args.Length != 5)
Console.WriteLine("Usage: addcert cert.pfx /r LocalMachine /s My /pass mypass");
string path = args[0];
StoreLocation sl = (StoreLocation)Enum.Parse(typeof(StoreLocation), args[2]);
StoreName sn = (StoreName)Enum.Parse(typeof(StoreName), args[4]);
X509Store store = new X509Store(sn, sl);
store.Open(OpenFlags.ReadWrite);
if (args.Length == 5)
store.Add(new X509Certificate2(path));
else if (args.Length == 7)
store.Add(new X509Certificate2(path, args[6]));
store.Close();
}
}
}
To use that, you can simply compile to the exe, and run that from a batch file like anything else you can do.
Enjoy :)