From 2373dddfba35143ced7e9c84c3fd7f347ff317ba Mon Sep 17 00:00:00 2001 From: Guillaume Chanaud Date: Wed, 11 Apr 2018 10:05:10 +0200 Subject: [PATCH] Better Implementation for OSPP detection 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 --- .vs/officepack/v15/.suo | Bin 0 -> 15360 bytes agent/msofficekey.vbs | 143 ++++++++-------------------------------- 2 files changed, 28 insertions(+), 115 deletions(-) create mode 100644 .vs/officepack/v15/.suo diff --git a/.vs/officepack/v15/.suo b/.vs/officepack/v15/.suo new file mode 100644 index 0000000000000000000000000000000000000000..d5bd6e438b325c7d4c27c3ec90c6ee55cd4dc234 GIT binary patch literal 15360 zcmeHN%X1?~8E@~BKmuf0mMjngn6NAhj_i@Gmp56nqnGutWJ|K-2Ljd}>t)G$TatIZ zRXOKCapOvIfE!hiqKZo{+@L736e)@$9H^o=@eh#Y_nXnI$FeL-w%M#z`cywnPft&O z{q^H}^z@?-uKxXMN@Oj`G@CD#y;8lR{P%pfKG_PO5^^@&1pN;6*=z*uX{+E0Q z>;LZgt^a}7-#yI3(fUUxfb>~N9YQ@o9Zs9iwfZT5YnK>g{a@U4OG0&HCkmM|u=stv9SMYW8z z6Dp+ryNog~0R8e$qAce&iFTh>z6#sB0juamI|{h33EeYDp(SrPTj}R^2{@ z|FI6fx?OjpUP`*tu6afE0=AIbL<>r2M-E(bD)$4fYSYy}3G!1G+T(uZ_o1wx3m(*q ze;nM|Gj7!rqSthkCc&S4bvjz&Xb$y>o*RQ?1$Cq~8MS^+L*fi_t14&hiT=jn>+9f8 zT~2+)HXMH1{mz5zpSK?^icNT*A#kf68RLX-bg#gW`x^MuFQR_zm%kfj>93Joke(}` zCK8Z2g;76lrfKCn|1tknzT{2neBSNe*#B<%nOyj5EFQZ!e zilk2dPP8F~Hss-rm(U|zbG_Pe3;nPAp#94KJ@BOuPU_@OeW0KP<({ifdzb$=Pci@J z@Sd)Jy7AYv%obX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v*GIj{d*Lzqwjy(S;wdS{f~YBaZ#uC(mctN&%Ns_VRZgaJO6ea9l|lx`=!_Q zoX`KMXF2G@_sjqA`M=KdUyOYRI{z{7`9H>WdfaO~*>cMBAL>~$o>}NuevS=eO;QZ8 zu+omy8i?Td6|@Sw-FYr?5?}vI_$IprTg{VE^gc*)r#Sy|5AW&cZ&=4!iE`^SXkEi{ z{&SG?ucPyy2YRaW{MqRI=Y>1}ImWZkF9Xy8{j7iE`A@z4Y5o6E{Gj*X#k~Fx4FJpk literal 0 HcmV?d00001 diff --git a/agent/msofficekey.vbs b/agent/msofficekey.vbs index 8993dce..bfc1d79 100644 --- a/agent/msofficekey.vbs +++ b/agent/msofficekey.vbs @@ -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 @@ -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 @@ -181,23 +182,25 @@ Sub writeXML(oVer,oProd,oProdID,oBit,oGUID,oInstall,oKey,oNote) "" 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 @@ -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 @@ -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 @@ -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)