Click here to Skip to main content
15,887,027 members
Articles / General Programming / String
Tip/Trick

How to run Makecert without password window?

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
13 Nov 2010CPOL 22.9K   2   2
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)


Written By
Architect
Germany Germany
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions

 
QuestionMakecert auto fill password is not working on minimized/closed vm. Pin
shravan chaurasiya19-Mar-19 19:42
shravan chaurasiya19-Mar-19 19:42 
QuestionHow to run Makecert without password window? Pin
Betim Prevalla28-May-13 4:05
Betim Prevalla28-May-13 4:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.