Please take a look at this webpage and specifically the extract below. Is there anyway for a script to be produced to create a report showing machine names with product keys? Additionally, for the information to be visible within Software Inventory for each machine on ITSM?
For a copy of Office you want to activate with the above product key, expand the Office entry and get the product code. You’ll need to click on the “View your product key” link and the key will expand. Keep that handy for later.
Open up a “Command Prompt” or “Powershell” as an administrator or (admin) user.
Run this command to see what product keys are currently installed:
cscript “C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs” /dstatus
Output: Each entry will list “Last 5 characters of installed product key: XXXXX”
For each key above, use this command to remove it. For two keys listed in step 3, run this command twice:
cscript “C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs” /unpkey:XXXXX
Output: You’ll see a success indicator.
Once all keys are removed, add the product key you gathered from “View your product key”:
cscript “C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs” /inpkey:HGEW3-DCD22-33WSA-4325J-PUR34
Output: You’ll see a success indicator.
Finally, activate Office. If you’ve installed the most recent key, and your computer is on the Internet, run this:
cscript “C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs” /act
Output: You’ll see a success indicator, something to the effect of “Activation Successful”.
A Note: if your Office installation is 64 Bit, remove ” (x86)” from each of the commands listed above. This will point you to the right script.
As per the commands you have provided this script has done. You have provided only for “Office16”, this script will work for all versions of Office which is installed on the particular Device for your convenience.
NOTE:
key="XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" # Give your new Product key which is valuableto activate.
Output will have Responses for each and every Commands.
Please, let us know your feedback.
key="XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" # Give your new Product key which is valuable.
import os
import ctypes
import sys
import platform
import subprocess
import ctypes
import re
f='\ospp.vbs'
cmd1=' /dstatus'
cmd2=' /unpkey:'
cmd3=' /inpkey:'
cmd4=' /act'
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
def os_bits():
y=platform.machine()
if y=='AMD64':
return 64
else:
return 32
def get_version(c):
with disable_file_system_redirection():
os.chdir(c)
a=os.popen('Dir').read()
b=re.findall('Office(.*)' ,a)
d='office'+b[1]
return d
def run_cmd1():
with disable_file_system_redirection():
i=os.popen('"'+c+'"'+cmd1).read()
print "
"+i
j=re.findall('key:\s(.*)' ,i)
return j[0]
def run_cmd2():
with disable_file_system_redirection():
i=os.popen('"'+c+'"'+cmd2+z).read()
print "
"+i
def run_cmd3():
with disable_file_system_redirection():
i=os.popen('"'+c+'"'+cmd3+key).read()
print "
"+i
def run_cmd4():
with disable_file_system_redirection():
i=os.popen('"'+c+'"'+cmd4).read()
print "
"+i
x=os_bits()
if x == 64:
c="C:\Program Files (x86)\Microsoft Office"
else:
c="C:\Program Files\Microsoft Office"
y=get_version(c)
c=c+'\\'+y+f
z=run_cmd1()
run_cmd2()
run_cmd3()
run_cmd4()