PluginsOCSInventory-NG / officepack

Retrieve microsoft office keys
GNU General Public License v2.0
15 stars 27 forks source link

Fix for Office 2013 and output.txt path #41

Closed gehasia closed 4 years ago

gehasia commented 6 years ago

-Add a similar way to check office 2013 as the one for office 2016, there is no registry key, we must use the OSPP.vbs script to get the key for an Office 15 (Office 2013) install !

-Fix path for reading the output.txt as the current one is inconsistent with the way we create it (%USERPROFILE% vs C:\users\%USERNAME%). In a domain if you have the same name for an account in the domain and an account out of it, it will leads to a wrong path (domain won't be appended in the path with the %USERNAME% env var) :

eg : You have both a local Administrator and a MYDOMAIN administrator your C:\users directory will looks like this : C:\Users\administrator C:\Users\administrator.MYDOMAIN

if you execute the script onto the domain account, the output.txt will be created here : C:\users\administrator.MYDOMAIN\output.txt Be the actual code read it here : C:\users\administrator\output.txt

gehasia commented 6 years ago

References : https://github.com/PluginsOCSInventory-NG/officepack/issues/30 https://github.com/PluginsOCSInventory-NG/officepack/issues/24

gillesdubois commented 6 years ago

Hi,

Thx for your contribution, i will review this code asap.

It looks like you have some residual file from your IDE in your commit. Could you remove the visual studio related file ?

Regards, Gilles Dubois.

gehasia commented 6 years ago

I pushed a better version : Instead of duplicating code we loop over the existing version array to find an OSPP.VBS correct path, so it works for office 2013 (15) ans office 2016 (16) and future version just by adding the version to aOffID(n,1)

I refactored the code in the getOffice16Infos (now getOfficeOSPPInfos) to loop over the OSPP.vbs results as we can have multiple output : We must send back ALL the results to OCS server.

Fixes https://github.com/PluginsOCSInventory-NG/officepack/issues/30 (there was two issues reported in this issue)

gehasia commented 6 years ago

Hi,

can you just pick this one ? : https://github.com/gehasia/officepack/commit/f7ce2a6667491c902c2785374b7d3fac43e8cfb0

gillesdubois commented 6 years ago

No you need to add a new commit that remove the file :)

gehasia commented 6 years ago

Ok it should be better now, i'm a donkey with git, sorry !

In fact, i did this patch for our internal use so there is multiple things in this commit, hope it's ok for you (i can split it up if really needed): -Fix path for output.txt parsing -Add support for OSPP.VBS from Office 15 and above (office 2013 H&B use the script, not the registry) -Add support for multiple installation of the same edition

I'm not a vbscript programmer, it's the first time i put my hand on it, hope this patch is not too ugly !

gehasia commented 6 years ago

Hi !

any news on this one ?

ajavor commented 6 years ago

Hi gehasia

I used your modifications. The script creates the file correctly in the% USERPROFILE% \ output.txt directory, but unfortunately it does not enter the XML code into the result file, so the data is not displayed in ocs-reports.

gehasia commented 6 years ago

Hi @ajavor

You must have a raw ospp output in your output.txt not xml. This file is then parsed to ouptut xml to standard output (you won't have any file with xml it's streamed on the std output)

Can you run in a cmd shell cscript "C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS" /dstatus (replace Office16 by the correct version installed on your system, it may be in C.\program files\ instead of c:\Program Files (x86)\ too, so please correct the path accordingly) you should have an output containing this kind of output

PRODUCT ID: xxxxx
SKU ID: xxxx
LICENSE NAME: Office 16, Office16HomeBusinessR_Retail3 edition
LICENSE DESCRIPTION: Office 16, RETAIL channel
BETA EXPIRATION: 01.01.1601
LICENSE STATUS:  ---LICENSED--- 
Last 5 characters of installed product key: XXXXX

Does this works ? If this is the case can you give me the path you entered to execute the ospp.vbs script ? if you execute msofficekey.vbs in a cmd shell, does the output.txt remains empty or it contains the same raw output ? If it contains the same raw output do you see a dialog box on screen with the xml version of this output or nothing appear ? Something like this : image

Maybe you have solved it by yourself since your post, i didn't see it before today...

ajavor commented 6 years ago

Hi @gehasia

When I run from the command line everything is ok: cscript

When I run the .vbs script with your changes (on user privileges by doubleclik) - nothing is displayed. In the user's profile path there is an output.txt file with the content: vbs_output

Personally, I dealt with it in a more primitive way - I copied the "getOffice16Infos" function and gave it the new name "getOffice15Infos". In the new function, I just modified the paths to the cscript file - and that's how it works.

gehasia commented 6 years ago

Hi @ajavor Did you copy the getOffice16Infos in my patched version or in the original version ?

Because there is no more getOffice16Infos in my version, so if you have one, maybe you have a in-between version. It has been replaced by a function called getOfficeOSPPInfos(version)

This function is called sequentially with every office version declared in the header of the file in a loop :

Dim aOffID(5,1)
aOffID(0,0) = "XP"
aOffID(0,1) = "10.0"
aOffID(1,0) = "2003"
aOffID(1,1) = "11.0"
aOffID(2,0) = "2007"
aOffID(2,1) = "12.0"
aOffID(3,0) = "2010"
aOffID(3,1) = "14.0"
aOffID(4,0) = "2013"
aOffID(4,1) = "15.0"
aOffID(5,0) = "2016"
aOffID(5,1) = "16.0"

...

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
  aOSPPVersions = Split(aOffID(a,1), ".")
  getOfficeOSPPInfos(aOSPPVersions(0))
Next

So the script should call every possible path to call the Microsoft script and get the licensing infos.

In your case it seems to write output for an invalid path on the Office15 path and never try with Office16 path. Are you sure you are using the latest version i did ? https://raw.githubusercontent.com/PluginsOCSInventory-NG/officepack/5fe18ee62fcc388117ea930a6a2f08e00377039e/agent/msofficekey.vbs

If it's the case i'll try to implement another way of checking for script presence in path (i did not modify this check from the original version)

ajavor commented 6 years ago

I made changes manually, probably somewhere I had to make a mistake. When I downloaded the .vbs script from the above link it looks like it works ok - the window is displayed and the data is correctly saved in the output.txt file.

Now I have to check on some other station where I have both Office 16 and Visio 16 installed.

ps. Additional function "getOffice16Infos" and "getOffice15Infos" was made on the older version of the file, in the one in which there was the function "getOffice16Infos".

ajavor commented 6 years ago

I checked and works great. screenshot_2018-10-01 ocs inventory

It would be good to add in the "Office Key Manager" tab all versions for which you need to buy a separate license, ie:

At the moment, the above are landing in the group "Office 16, RETAIL channel" or "Office 15, RETAIL channel" or "365".

If the above will be introduced, then You will be able to safely increase plugin to the 3.0 version :)

gehasia commented 5 years ago

Last commit made to fix Office 2013 issues https://github.com/PluginsOCSInventory-NG/officepack/issues/51

@gillesdubois : Hi ! I'm pretty confident that the differents fixes i made resolve some issues users are reporting frequently. Is there any schedule to pull the changes and update the plugin version ? Tell me if you wanna see some changes on the PR !

charleneauger commented 4 years ago

Hi @gehasia ,

Sorry for the delay. I tested your PR and all is good ! Thanks for your contribution !

Best regards, Charlene Auger