Why won't my Lync 2013 client install?

Ok, we all have our new shiny installs of Lync 2013 client with the recent Office service updates.  The new client has been downloaded from the new portal and hurriedly installed on your machine.  But, oh no, it fails to install!  It installs on other machines ok and other colleagues are enjoying the wonders of Lync 2013 :(

This is what you see when you try to install the client from the installation media:

"Microsoft Lync Basic 2013 encountered an error during setup "

Oh dear... That's not good.

Ok lets look into the MSI install log, inside it we see:

2013/05/03 16:01:14:024::[16752] Successfully
installed package: LyncEntryWW path:C:\MSOCache\All

2013/05/03 16:01:14:025::[16752] 05/03/2013 16:01:14
Committing MSI transaction.

2013/05/03 16:01:44:089::[16752] Error:
MsiEndTransaction failed. MsiEndTransaction ErrorCode: 1603(0x643).

2013/05/03 16:01:44:089::[16752] WER element
[P4] is set to value [1603]

2013/05/03 16:01:44:089::[16752] WER element
[P7] is set to value [1603]

2013/05/03 16:01:44:089::[16752] WER element
[P6] is set to value [%s %s]

2013/05/03 16:01:44:089::[16752] WER element [P6] is converted to [FC73469E]

2013/05/03 16:01:44:091::[14288] Showing
completion dialog.   

Hmmm a MsiEndTransaction failed... With an error 1603.

So looking further into this, it looks like the WMI repository is corrupted.  We can have a quick go in repairing and seeing if all is well with system files by trying to run this at the command prompt:

sfc /scannow

SFC is a system file checking tool which I think was included in Windows 2000 and now is in every version of windows.  You can read more about it here http://technet.microsoft.com/en-us/library/bb491008.aspx.

That might not sort out your problem, it might be that we need to do major surgery.  You can do this by running this script as a batch file:

@echo off
sc config winmgmt start= disabled
net stop winmgmt /y
cd %windir%\system32\wbem
if exist repository.old rmdir /s/q repository.old
rename repository repository.old
for /f %%s in ('dir /b *.dll') do regsvr32 /s %%s
wmiprvse /regserver
winmgmt /regserver
net start winmgmt
net start SharedAccess
net start CcmExec

This should clear out the old repository and create a new one. 

Remember: This solution is presented as an solution to the issue being described and you run it on your own machines at your own risk!  

This should get things working.  I'm told that this also fixes an issue with Office 2013 not installing.  I've yet to test it, but please let me know if that is the case.