Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming / string

How to run Makecert without password window?

5.00/5 (1 vote)
13 Nov 2010CPOL 23.3K  
How to run makecert only in command string mode?
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 );
		// Enter Private key Pass
		shell.SendKeys( defaultPassword );
		WScript.Sleep( 300 );
		shell.SendKeys( "{ENTER}" );
		WScript.Sleep( 500 );
		passIsEntered = true;
	}
	WScript.Sleep( 500 );
	timeOut ++;
}
WScript.Sleep( 1000 );

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)