@echo off

setlocal EnableDelayedExpansion

cd /d %~dp0

if "%1"=="hidecmd" goto begin

net session >nul 2>&1
if !errorLevel! == 0 (
    net user dynamsoftlts
    if !errorLevel! == 0 (
        rem
    ) else (
        net user dynamsoftlts x8d*i3cLT07s /add
        icacls "%~dp0." /grant dynamsoftlts:^(OI^)^(CI^)F /T
        echo "User dynamsoftlts is added"
    )
    ::echo. | runas /user:dynamsoftlts "%~f0"
    ".\win\bin\PsExec64" -u dynamsoftlts -p x8d*i3cLT07s -accepteula "%~f0"
    goto end
)

start mshta vbscript:createobject("wscript.shell").run(".\startup.bat hidecmd",0)(window.close)&&exit

:begin

if not exist ".\win\jre\bin\dynamsoftdls.exe" (
    echo f | xcopy /d ".\win\jre\bin\java.exe" ".\win\jre\bin\dynamsoftdls.exe"
)

".\win\bin\dynamsoftdlsx" ".\win\jre\bin\dynamsoftdls" -Djavax.net.ssl.trustStoreType=WINDOWS-ROOT --add-opens java.base/jdk.internal.loader=ALL-UNNAMED -jar ".\dls-2.4.11.jar" --server.port=48080 --data.port=30201

:end

endlocal
