Skip to content

Commit

Permalink
Better Implementation for OSPP detection
Browse files Browse the repository at this point in the history
Instead of duplicating the code for each version, we loop on the potential path for OSPP detection.

We loop over the OSPP results for potential multi-products installation to send back the correct XML
  • Loading branch information
gehasia committed Apr 11, 2018
1 parent 507d6b8 commit f7ce2a6
Showing 1 changed file with 28 additions and 115 deletions.
143 changes: 28 additions & 115 deletions agent/msofficekey.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ aOffID(4,1) = "15.0"
aOffID(5,0) = "2016"
aOffID(5,1) = "16.0"

Dim aOSPPVersions

Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
oCtx.Add "__ProviderArchitecture", 64

Expand All @@ -56,12 +58,11 @@ schKey2K "Visio", "SOFTWARE\" & wow & "Microsoft\Visio\6.0\", Array("B66F45DC"),

For a = LBound(aOffID, 1) To UBound(aOffID, 1)
schKey "SOFTWARE\Wow6432Node\Microsoft\Office\" & aOffID(a,1) & "\Registration", false
schKey "SOFTWARE\Microsoft\Office\" & aOffID(a,1) & "\Registration", true
schKey "SOFTWARE\Microsoft\Office\" & aOffID(a,1) & "\Registration", True
aOSPPVersions = Split(aOffID(a,1), ".")
getOfficeOSPPInfos(aOSPPVersions(0))
Next

getOffice15Infos
getOffice16Infos

Sub schKey97(regKey)
oReg.GetStringValue HKEY_LOCAL_MACHINE, regKey & "Office\8.0", "BinDirPath", oDir97
If IsNull(oDir97) Then Exit Sub
Expand Down Expand Up @@ -181,23 +182,25 @@ Sub writeXML(oVer,oProd,oProdID,oBit,oGUID,oInstall,oKey,oNote)
"</OFFICEPACK>"
End Sub

Sub getOffice15Infos
Sub getOfficeOSPPInfos(version)
Dim WshShell, oExec
Dim mTab
Dim key, value
Dim path
Dim writeProduct

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshShellObj = WScript.CreateObject("WScript.Shell")
Set WshProcessEnv = WshShellObj.Environment("Process")

result = WshShell.Run("cmd /c cscript ""C:\Program Files (x86)\Microsoft Office\Office15\OSPP.VBS"" /dstatus > %USERPROFILE%\output.txt", 0, true)
result = WshShell.Run("cmd /c cscript ""C:\Program Files (x86)\Microsoft Office\Office" & version & "\OSPP.VBS"" /dstatus > %USERPROFILE%\output.txt", 0, true)
' Debug : if 32 bits version available ?
' wscript.echo result

' If file not there command throw an error and return is 1 and abover
if result > 0 then
' Try with the 64 bits version if available
result = WshShell.Run("cmd /c cscript ""C:\Program Files\Microsoft Office\Office15\OSPP.VBS"" /dstatus > %USERPROFILE%\output.txt", 0, true)
result = WshShell.Run("cmd /c cscript ""C:\Program Files\Microsoft Office\Office" & version & "\OSPP.VBS"" /dstatus > %USERPROFILE%\output.txt", 0, true)
' Debug : if 64 bits version available ?
' WScript.Echo result
end If
Expand All @@ -207,100 +210,10 @@ Sub getOffice15Infos
Set fso = CreateObject("Scripting.FileSystemObject")
' The USERNAME env var doesn't take the domain part into account which leads to a wrong directory which cannot be read
path = WshProcessEnv("USERPROFILE") & "\output.txt"
Set file = fso.OpenTextFile(path, 1)
'strData = file.ReadLine

Do Until file.AtEndOfStream
' Debug : echo each line
' WScript.echo file.ReadLine

str = file.ReadLine
' Debug : Show string before split
' WScript.Echo str

mTab = Split(str, ":")
arrCount = uBound(mTab) + 1

If arrCount > 1 then
key = mTab(0)
value = mTab(1)

Select Case key
Case "PRODUCT ID"
oProdID = mTab(1)
' Debug : echo office data
' WScript.echo "oProdId = " & oProdID
Case "SKU ID"
oGUID = mTab(1)
' Debug : echo office data
' WScript.echo "oGUID = " & oGUID
Case "LICENSE NAME"
oProd = mTab(1)
' Debug : echo office data
' WScript.echo "oProd = " & oProd
Case "LICENSE DESCRIPTION"
oVer = mTab(1)
' Debug : echo office data
' WScript.echo "oVer = " & oVer
Case "ERROR DESCRIPTION"
oNote = mTab(1)
' Debug : echo office data
' WScript.echo "oNote = " & oNote
Case "Last 5 characters of installed product key"
oKey = "XXXXX-XXXXX-XXXXX-XXXXX-" & mTab(1)
' Debug : echo office data
' WScript.echo "oKey = " & oKey
End Select
End If

Loop

oInstall = 1
oBit = 1

file.Close

'Check if Office is 365
If InStr(oProd, "O365") > 0 Then
oVer = "365"
oProd = Right(oProd, len(oProd)-11)
If oProd = " Office15O365BusinessR_Subscription edition" Then oProd = "Microsoft Office Business Subscription Edition 365" : End If
If oProd = " Office15O365BusinessR_Grace edition" Then oProd = "Microsoft Office Business Grace Edition 365" : End If
End if
writeXML oVer,oProd,oProdID,oBit,oGUID,oInstall,oKey,oNote
End If

End Sub

Sub getOffice16Infos
Dim WshShell, oExec
Dim mTab
Dim key, value
Dim path
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshShellObj = WScript.CreateObject("WScript.Shell")
Set WshProcessEnv = WshShellObj.Environment("Process")

result = WshShell.Run("cmd /c cscript ""C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS"" /dstatus > %USERPROFILE%\output.txt", 0, true)
' Debug : if 32 bits version available ?
' wscript.echo result

' If file not there command throw an error and return is 1 and abover
if result > 0 then
' Try with the 64 bits version if available
result = WshShell.Run("cmd /c cscript ""C:\Program Files\Microsoft Office\Office16\OSPP.VBS"" /dstatus > %USERPROFILE%\output.txt", 0, true)
' Debug : if 64 bits version available ?
' WScript.Echo result
end If

' Result = 0 if successfully executed
if result = 0 then
Set fso = CreateObject("Scripting.FileSystemObject")
' The USERNAME env var doesn't take the domain part into account which leads to a wrong directory which cannot be read
path = WshProcessEnv("USERPROFILE") & "\output.txt"
Set file = fso.OpenTextFile(path, 1)
'strData = file.ReadLine

writeProduct = 0
Do Until file.AtEndOfStream
' Debug : echo each line
' WScript.echo file.ReadLine
Expand All @@ -318,6 +231,7 @@ Sub getOffice16Infos

Select Case key
Case "PRODUCT ID"
writeProduct = 1
oProdID = mTab(1)
' Debug : echo office data
' WScript.echo "oProdId = " & oProdID
Expand All @@ -341,26 +255,25 @@ Sub getOffice16Infos
oKey = "XXXXX-XXXXX-XXXXX-XXXXX-" & mTab(1)
' Debug : echo office data
' WScript.echo "oKey = " & oKey
End Select
End Select
Else
If writeProduct = 1 Then
oInstall = 1
oBit = 1
'Check if Office is 365
If InStr(oProd, "O365") > 0 Then
oVer = "365"
oProd = Right(oProd, len(oProd)-11)
If oProd = " Office16O365BusinessR_Subscription edition" Then oProd = "Microsoft Office Business Subscription Edition 365" : End If
If oProd = " Office16O365BusinessR_Grace edition" Then oProd = "Microsoft Office Business Grace Edition 365" : End If
End if
writeXML oVer,oProd,oProdID,oBit,oGUID,oInstall,oKey,oNote
writeProduct=0
End If
End If

Loop

oInstall = 1
oBit = 1

file.Close

'Check if Office is 365
If InStr(oProd, "O365") > 0 Then
oVer = "365"
oProd = Right(oProd, len(oProd)-11)
If oProd = " Office16O365BusinessR_Subscription edition" Then oProd = "Microsoft Office Business Subscription Edition 365" : End If
If oProd = " Office16O365BusinessR_Grace edition" Then oProd = "Microsoft Office Business Grace Edition 365" : End If
End if
writeXML oVer,oProd,oProdID,oBit,oGUID,oInstall,oKey,oNote
file.Close
End If

End Sub

Function decodeKey(iValues)
Expand Down

0 comments on commit f7ce2a6

Please sign in to comment.