@echo off
REM  RAID800                               
REM  Perl Install tool for RAID800 SVP
REM       All Rights Reserved, Copyright (C) 2020,Hitachi, Ltd. 
REM
REM History  :Version    :DATE        : Coder        : Patch No
REM RAID 800 
REM          :01-00      :2020.01.28  : T.Yamanaka   : #97547 (Strawberry Perl 5.28.2 is supported) 
REM
REM Document
REM   System Environment "Path" Delete (End ";" Put Only)
REM     Paramater %1 Delete Path(Do not put ";")
REM
REM 
set DBG=
REM set DBG=echo
set REG_KEY="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
set DelPath=
set DelPath=%~1

if "'%DelPath%'" equ "''" goto :NotParam

FOR /F "TOKENS=1,2,*" %%I IN ('reg query %REG_KEY% /v Path') DO IF "%%I"=="Path" SET PathVal=%%K

call set PathVal=%%PathVal:^"=%%
if "'%PathVal%'" equ "''" goto :RegErrEnd

echo "%PathVal%" | findstr /I "%DelPath%" >NUL
if not %ERRORLEVEL% equ 0 goto :AlreadyDeleted

call set PathVal=%%PathVal:%DelPath%^;=%%

rem %DBG% reg add %REG_KEY% /v Path /t REG_SZ /d "%PathVal%" /f
%DBG% setx /M path "%PathVal%"

exit /b 0

:AlreadyDeleted
echo Already Deleted
exit /b 0

:NotParam
echo Paramater Error
exit /b 1

:RegErrEnd
echo Registry Fail
exit /b 1
