Wednesday, April 15, 2015

Remotely Rearming Microsoft Office 2010/2013

Tesla Robot Dance by Steve Jurvetson is licenses CC BY 2.0.
When it comes to work, I live and die by the following motto:
If it's worth doing twice, it's worth doing automatically.
With that motto in mind, I ran into an issue. When setting up our computer lab image, I forgot to rearm the source image's Microsoft Office installations - this caused all of our lab PCs to share the same Office activation ID, which in turn led our KMS server to attempt to activate them as if they were all the same computer. Consequently, within a week, I faced some rather confused coworkers who were wondering why Microsoft Office was telling them that it wasn't properly licensed. Meanwhile, whenever I fired up VAMT to perform a volume activation via KMS, each of the client PCs reported the following error message:
0xC004F038 The software Licensing Service reported that the computer could not be activated. The count reported by your Key Management System (KMS) is insufficient. Please contact your system administrator.
When I checked the activation count on our KMS server for Microsoft Office (cscript slmgr.vbs /dlv all), I noticed that the current count was 1 - since we definitely have more than one computer in our computer lab, something clearly wasn't right. This led to a bit of Google sleuthing, which revealed articles that addressed this very issue for Microsoft Office 2010 and Microsoft Office 2013. Trouble was, I was in no position to re-image all of our computer labs, nor was I in a mood to walk up to an innumerable number of PCs and manually run a script, nor was I in a mood to reboot every single computer in the building.

Luckily, I didn't have to. Thanks to psexec, a rather handy part of the Sysinternals Suite, I was able to modify the script for remote execution:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET _OSPPreArmPath="C:\Program Files (x86)\Common Files\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPREARM.EXE"
SET _OSPP10Path="C:\Program Files (x86)\Microsoft Office\Office14\ospp.vbs"
SET _OSPP13Path="C:\Program Files (x86)\Microsoft Office\Office15\ospp.vbs"

FOR /F "tokens=2 delims=,= usebackq" %%G IN (`dsquery computer ou^=Your PC OU^,dc^=YourInternalDomain^,dc^=YourInternalDomainSuffix -limit 0`) DO (
        SET _Target=^\^\%%G
        ECHO:Rearming Office...
        PSEXEC !_Target! %_OSPPreArmPath%
        PSEXEC !_Target! cscript.exe /nologo %_OSPP10Path% /act
        PSEXEC !_Target! cscript.exe /nologo %_OSPP13Path% /act
        PSEXEC !_Target! reg add "HKLM\Software\Microsoft\Office\14.0\Common\OSPPREARM" /f
        PSEXEC !_Target! reg add "HKLM\Software\Microsoft\Office\15.0\Common\OSPPREARM" /f
)


Some caveats:
  • This assumes that you're using a 32-bit installation of Microsoft Office on your PCs, which, unless you're dealing with really big Excel files or something, you probably should be.
  • It assumes that all of your PCs are in the same OU, or at least are all nested inside the same OU. Note that you can run this on a parent OU and it'll work on all PCs in any child OUs.
  • Make sure to fill in YourInternalDomain and YourInternalDomainSuffix with information appropriate for your environment.
  • You'll need to run this script in an administrative command prompt from a directory that contains psexec - or, alternatively, you'll need to copy psexec to some place previously listed in your PATH, or add the location of psexec to your PATH.
  • All of the affected computers will need to be on.
  • I personally found that, even after running this script, it wasn't a bad idea to double-check licensing information in VAMT and reactivate any PCs that were Out of Grace. I will note, though, that the KMS server actually did hand out licenses successfully to those PCs after running this script.
If you need to run the script on a particular computer:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET _OSPPreArmPath="C:\Program Files (x86)\Common Files\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPREARM.EXE"
SET _OSPP10Path="C:\Program Files (x86)\Microsoft Office\Office14\ospp.vbs"
SET _OSPP13Path="C:\Program Files (x86)\Microsoft Office\Office15\ospp.vbs"

SET _Target=^\^\%1
ECHO:Rearming Office...
PSEXEC %_Target% %_OSPPreArmPath%
PSEXEC %_Target% cscript.exe /nologo %_OSPP10Path% /act
PSEXEC %_Target% cscript.exe /nologo %_OSPP13Path% /act
PSEXEC %_Target% reg add "HKLM\Software\Microsoft\Office\14.0\Common\OSPPREARM" /f
PSEXEC %_Target% reg add "HKLM\Software\Microsoft\Office\15.0\Common\OSPPREARM" /f


Then just save the script and call it with scriptname.cmd computername (e.g. reactivateoffice.cmd LABPC-1). The same caveats as above more or less apply.

No comments:

Post a Comment