When you run the
makecert.exe to create a certificate, usually you get a GUI that asks you to enter the password. This is ok, when you run the tool manually, but not when you want to automatize the process of the certificate creation. For this goal, you can create a JavaScript file and copy the code below. It waits for the window, enters the password and repeats it for the private certificate. Then it closes itself. If the timeout expires, it closes the application after a while.
File
MakeCertNoGUI.js
:
var programArgs = WScript.Arguments;
var defaultPassword = "P@$$w0rd";
var maxItirations = 500;
if ( programArgs.Count() > 0 ) {
defaultPassword = programArgs(0);
}
var shell = WScript.CreateObject("WScript.Shell");
var passIsEntered = false;
WScript.Sleep(1000);
var timeOut = 0;
while (!passIsEntered && timeOut < maxItirations)
{
var isActivated = shell.AppActivate("Create Private Key Password");
WScript.Sleep( 500 );
if (isActivated)
{
shell.SendKeys( defaultPassword );
WScript.Sleep( 300 );
shell.SendKeys( "{TAB}" );
WScript.Sleep( 300 );
shell.SendKeys( defaultPassword );
WScript.Sleep( 300 );
shell.SendKeys( "{TAB}" );
WScript.Sleep( 300 );
shell.SendKeys( "{ENTER}" );
WScript.Sleep( 500 );
shell.SendKeys( defaultPassword );
WScript.Sleep( 300 );
shell.SendKeys( "{ENTER}" );
WScript.Sleep( 500 );
passIsEntered = true;
}
WScript.Sleep( 500 );
timeOut ++;
}
WScript.Sleep( 1000 );