Skip to content

Commit

Permalink
Merge pull request #41 from gehasia/Office-2013-support
Browse files Browse the repository at this point in the history
Fix for Office 2013 and output.txt path
  • Loading branch information
charleneauger authored Jun 22, 2020
2 parents 7e881d7 + 0e0b07f commit c7bc7fb
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 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,11 +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

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 @@ -180,32 +182,38 @@ Sub writeXML(oVer,oProd,oProdID,oBit,oGUID,oInstall,oKey,oNote)
"</OFFICEPACK>"
End Sub

Sub getOffice16Infos
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\Office16\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\Office16\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
end If

' Result = 0 if successfully executed
if result = 0 then
if result = 0 Then
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\Users\" & WshProcessEnv("USERNAME") & "\output.txt", 1)
' 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 @@ -217,16 +225,18 @@ Sub getOffice16Infos
mTab = Split(str, ":")
arrCount = uBound(mTab) + 1

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

Select Case key
Case "PRODUCT ID"
writeProduct = 1
oProdID = mTab(1)
' Debug : echo office data
' WScript.echo "oProdId = " & oProdID
Case "SKU ID"
writeProduct = 1
oGUID = mTab(1)
' Debug : echo office data
' WScript.echo "oGUID = " & oGUID
Expand All @@ -246,26 +256,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 c7bc7fb

Please sign in to comment.