I would like to suggest a different approach...
Make these changes to C:\wamp\scripts\switchWampPort.php
Change line 21 to this...
$httpdFileContents = preg_replace($findTxtRegex,'${1}'.$portToUse, $httpdFileContents, 1);
Add this...
//Grab Currently Used Port
$portInUse = $wampConf['apachePortUsed'];
Above this ..
//Replace Used Port by New port ($_SERVER['argv'][1])
$portToUse
Forum:
WampServer English