@echo OFF
setlocal ENABLEEXTENSIONS

:AppDataMethod
rem Doesn't require Elevated permissions - Installs in AppData
SET LicensePathFolder="%APPDATA%\ModuleWorks"
SET LicensePath="%LicensePathFolder%\plugins.lic"
SET Content=v10mwY8DF9HVEYwDTti3zQU9dk9YD8JSR3M

IF NOT EXIST %LicensePathFolder% mkdir %LicensePathFolder%

ECHO %Content% > %LicensePath% || (
    ECHO Failed writing file
    GOTO End
)

rem Success!
ECHO Plugins successfully unlocked!

GOTO End

:OriginalMethod
rem Requires Elevated permissions - Installs in same location as Installer
rem Retrieve installer path from Registry
SET KeyName="HKEY_LOCAL_MACHINE\Software\ModuleWorks"
SET KeyValueName=PluginInstallerPath

FOR /F "usebackq tokens=1,2,*" %%A IN (`REG QUERY %KeyName% /v %KeyValueName% 2^>nul`) DO (
    SET ValueName=%%A
    SET ValueType=%%B
    SET ValueValue=%%C
)

ECHO ----

IF defined ValueName (
    rem ECHO Value Name = %ValueName%
    rem ECHO Value Type = %ValueType%
    ECHO Installer Path = %ValueValue%
) ELSE (
    rem ECHO %KeyName%\%KeyValueName% not found.
    ECHO Registry entry not found
    ECHO Make sure the Plugin Installer has been installed before running this script.
    GOTO End
)

rem Extract directory from path
ECHO ----
FOR %%i IN ("%ValueValue%") DO (
SET Filedrive=%%~di
SET Filepath=%%~pi
SET Filename=%%~ni
SET Fileextension=%%~xi
)
SET Directory=%Filedrive%%Filepath%
ECHO Directory = %Directory%

rem Write file
ECHO ----
SET LicensePath="%Directory%plugins.lic"
SET Content=v10mwY8DF9HVEYwDTti3zQU9dk9YD8JSR3M
ECHO %LicensePath%
ECHO %Content% > %LicensePath% || (
    ECHO Failed writing file. You may need to run the script as administrator
    GOTO End
)

rem Success!
ECHO Plugins successfully unlocked!

:End
PAUSE