@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment

::--- Batch section within JScript comment ----------------------------
@echo off

::This block of code handles the TEE by calling the internal JScript code
if "%~1"=="_TEE_" (
  cscript //E:JScript //nologo "%~f0" %2 %3
  exit /b
)

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------

break > log.txt

reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT

if %OS%==32BIT echo This is a 32bit operating system | "%~f0" _TEE_ log.txt 1

if %OS%==64BIT echo This is a 64bit operation system | "%~f0" _TEE_ log.txt 1

ver | find "XP" > NUL && set version=XP || set version=NEWER

if %version%==XP set scCommand=sc

if %version%==NEWER set scCommand=sc \\localhost

set swedaServiceName="Sweda SAT Service"

set swedaAppDir="%ProgramFiles%\Sweda"
if NOT EXIST %swedaAppDir% mkdir %swedaAppDir%

%scCommand% query %swedaServiceName% > nul
if ERRORLEVEL 1060 GOTO service_not_installed

for /F "tokens=3 delims=: " %%H in ('%scCommand% query %swedaServiceName% ^| findstr "        STATE"') do (
  if /I "%%H" EQU "RUNNING" ( @start /b cmd /c %scCommand% stop %swedaServiceName% | "%~f0" _TEE_ log.txt 1 )
)
for /F "tokens=3 delims=: " %%H in ('%scCommand% query %swedaServiceName% ^| findstr "        ESTADO"') do (
  if /I "%%H" EQU "RUNNING" ( @start /b cmd /c %scCommand% stop %swedaServiceName% | "%~f0" _TEE_ log.txt 1 )
)

echo[
echo Waiting for service to stop | "%~f0" _TEE_ log.txt 1

:wait_service_stop
for /F "tokens=3 delims=: " %%H in ('%scCommand% query %swedaServiceName% ^| findstr "        STATE"') do (
  if /I "%%H" NEQ "STOPPED" ( GOTO wait_service_stop )
)
for /F "tokens=3 delims=: " %%H in ('%scCommand% query %swedaServiceName% ^| findstr "        ESTADO"') do (
  if /I "%%H" NEQ "STOPPED" ( GOTO wait_service_stop )
)

echo Service stopped, removing it! | "%~f0" _TEE_ log.txt 1

%scCommand% delete %swedaServiceName% | "%~f0" _TEE_ log.txt 1

:service_not_installed

echo[
echo Installing new service! | "%~f0" _TEE_ log.txt 1

if %OS%==32BIT (
	copy service32.exe %swedaAppDir%\service.exe /y > nul
) else (
	copy service64.exe %swedaAppDir%\service.exe /y > nul
)

if NOT %ERRORLEVEL%==0 (
	echo Installation failed, error %ERRORLEVEL%! | "%~f0" _TEE_ log.txt 1
	EXIT /B 1
)

%scCommand% create %swedaServiceName% binPath= %swedaAppDir%\service.exe start= auto DisplayName= %swedaServiceName% | "%~f0" _TEE_ log.txt 1
if NOT %ERRORLEVEL%==0 (
	echo Service creation failed, error %ERRORLEVEL%! | "%~f0" _TEE_ log.txt 1
	EXIT /B 2
)

%scCommand% failure %swedaServiceName% reset= 60 actions= restart/1000/restart/1000/restart/1000 | "%~f0" _TEE_ log.txt 1
if NOT %ERRORLEVEL%==0 (
	echo Service configuration failed, error %ERRORLEVEL%! | "%~f0" _TEE_ log.txt 1
	EXIT /B 3
)

echo Service successfully installed! | "%~f0" _TEE_ log.txt 1

echo[
echo Starting service! | "%~f0" _TEE_ log.txt 1

%scCommand% start %swedaServiceName% | "%~f0" _TEE_ log.txt 1
if NOT %ERRORLEVEL%==0 (
	echo Starting Service failed, error %ERRORLEVEL%! | "%~f0" _TEE_ log.txt 1
	EXIT /B 4
)

echo Service successfully started! | "%~f0" _TEE_ log.txt 1

echo[
echo Exiting! | "%~f0" _TEE_ log.txt 1

exit /b

----- End of JScript comment, beginning of normal JScript  ------------------*/
var fso = new ActiveXObject("Scripting.FileSystemObject");
var mode=2;
if (WScript.Arguments.Count()==2) {mode=8;}
var out = fso.OpenTextFile(WScript.Arguments(0),mode,true);
var chr;
while( !WScript.StdIn.AtEndOfStream ) {
  chr=WScript.StdIn.Read(1);
  WScript.StdOut.Write(chr);
  out.Write(chr);
}
