How to input or change Office 2013 product key (VBScript)  

Introduction

This script sample shows how to input or change Office 2013 product key in Windows 8.

Scenarios

Sometimes due to some error, people cannot input or change their Office product key. This script can solve this problem.

Script

Step 1: Double click the script.

Step 2: Input the key.

Result:

 

Note To change Microsoft Office product key, the software must be installed at default place. If you customize the installation, please change the code to your installation root path.

ProgramFiles = objshell.ExpandEnvironmentStrings("%ProgramFiles%")

Here are some code snippets for your references.

VBS
Edit|Remove
If Len(value) <> 0Then 
    'Import office product key 
    Set Result = objshell.Exec("Cscript.exe """ & VBPath & """ /inpkey:" & value)
    Flag = False 
    Do While Not result.StdOut.AtEndOfStream 
        str = result.StdOut.ReadLine()
        If InStr(UCase(str),UCase("Error")) <> 0 Then 
            Flag = True 
        End If 
        WScript.Echo str
    Loop 
    'If importing failed, try again.
    If Flag = True  Then 
        WScript.Echo "Please try again."
        ChangeOffKey            
    Else
    'Try to active Office product 
        WScript.Echo "Try activing Office product."
        Set Result = objshell.Exec("Cscript.exe """ & VBPath & """ /act")
        Flag = False 
        Do While Not result.StdOut.AtEndOfStream 
            str = result.StdOut.ReadLine()
            WScript.Echo str
        Loop 
    End If 
Else 
    WScript.Echo "Action cancelled by user."
End If 

Prerequisite 

Windows 8 or later version

Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.