0

We have a work-at-home agreement with Microsoft and users are allowed to use Office 2010 on their personal machines (for work purposes only), at home.

In order to prevent the licence code from becoming known I have devised a method to automate their activation request, without my interaction.

Once installed, I've opted for;

@Echo Off
SETLOCAL
REM Check for Installation
if not exist "c:\Program Files (x86)\Microsoft Office\Office14\" goto NoSoftware
if not exist "c:\Program Files\Microsoft Office\Office14\" goto NoSoftware
GOTO CheckArchitecture
REM -----------------------------------------------------------------
:NoSoftware
*This section intentionally blank for further development*
REM -----------------------------------------------------------------
:CheckArchitecture
REM Check architecture
if exist "c:\Program Files (x86)" goto x64
Cscript c:\"Program Files (x86)"\"Microsoft Office"\Office14\ospp.vbs /inpkey:KEY-GOES-HERE
Cscript c:\"Program Files (x86)"\"Microsoft Office"\Office14\ospp.vbs /act
GOTO CreateDelMAK
REM -----------------------------------------------------------------
:x64
Cscript c:\"program files\Microsoft Office"\Office14\ospp.vbs /inpkey:KEY-GOES-HERE
Cscript c:\"program files\Microsoft Office"\Office14\ospp.vbs /act

which works wonders.

Now as the key is simply contained within a batch file, it's easily obtainable and thus needs to be masked. For this, I have opted to roll the batch up into an EXE so that it can be executed on their machine and the file cannot simply be viewed to obtain the license code.

Great, that all works perfectly well however the EXE will stay on their machine after the installation has completed, and this can then be re-run or redistributed, thus breaching the license agreement.

As I solution, I then added the following lines (following on from above) to the activation batch script;

REM -----------------------------------------------------------------
:CreateDelMAK
echo @Echo OFF > DeleteMAK.bat
echo CLS >> DeleteMAK.bat
echo Timeout 8 >> DeleteMAK.bat
echo DEL OfficeMAK.exe >> DeleteMAK.bat
echo (goto) 2>nul & del "%~f0" >> DeleteMAK.bat
REM -----------------------------------------------------------------
START DeleteMAK.bat
SET OfficeMAK=OfficeMAK.exe
TASKKILL /IM "%OfficeMAK%"

I read dbenham's post How to make .BAT file delete it self after completion? pertaining to the (goto) 2>nul & del "%~f0" trick with goto, and I though I could then use this in the end of DeleteMAK.bat so that it would self-destruct once processed. Formatting aside, the above gives me the following in a shiny new batch file;

Echo OFF
CLS
Timeout 5
DEL OfficeMAK.exe

My issue, as I'm sure you can all see from the above, is that I cannot get the original script to echo (goto) 2>nul & del "%~f0" over to the new file, so once the process completes, DeleteMAK.bat still exists, and it's just sloppy.

Further reading yields special characters need to be escaped, so I went with;

echo (goto) 2^>nul & del "%~f0" >> DeleteMAK.bat

initially, and finally moved on to;

echo (goto) 2^>nul & del "%~f0"^ >> DeleteMAK.bat

You can probably tell from my rather convoluted methodology that I am not a very proficient coder! I've made it fairly far using stackoverflow search, I feel like I'm almost there, but I can't nail it down.

Please, oh please, can one of you extremely talented people put me out of my misery? I'd be forever grateful!

Community
  • 1
  • 1
  • 1
    You need to escape the ampersand if you want it to be in your bat file. – Squashman Oct 27 '15 at 18:01
  • Jeep in mind [undelete](http://www.computerhope.com/undelete.htm) exists. As well, couldnt you echo `%0` into a temp file, then just delete the name stored in said file? – Bloodied Oct 27 '15 at 18:17
  • @Arescet, not in the Windows World, but your point is still valid as the most of the bat to exe converters dump a copy of the batch file into a temporary folder. The user could intercept the file that way as well. They could also hijack the DELETE command with their own delete command that could send a copy of the file to another folder or recycle bin. – Squashman Oct 27 '15 at 18:25
  • 1
    `echo (goto^) 2^>nul ^& del "%%~f0" >> DeleteMAK.bat` escaped `^>` and `^&` **and** `%%~f0`. Not sure about `^)` necessity but should not cause harm anyway. – JosefZ Oct 27 '15 at 23:31
  • @JosefZ that worked a treat, many thanks! – CriticalPoint Oct 29 '15 at 08:28

0 Answers0