@echo off setlocal DisableDelayedExpansion rem ** At this point the delayedExpansion should be disabled rem ** otherwise an exclamation mark in %* will be interpreted as special command SET HPSUM_CMD_ARGS=%* SET HPSUM_ROOT="%~dp0" rem remove trailing back slash IF "!HPSUM_ROOT:~-1!"=="\" SET HPSUM_ROOT=!HPSUM_ROOT:~0,-1! SET dstpath="!HPSUM_ROOT!" setlocal EnableDelayedExpansion SET REMOTE=0 SET SERVICERUNNING=0 SET ERRORCODE=0 IF "!TMPDIR!"=="" ( SET TMPDIR=%temp% ) ELSE ( echo TMPDIR is set to !TMPDIR! ) rem check whether it is Virtual mapped Drive rem check whether it is N/W mapped Drive or UNC path set virtualdrive=%~d0 - CD-ROM Drive FOR /F "tokens=*" %%A IN ('"fsutil fsinfo drivetype"" "%~d0""') do ( if /i "%%A"=="!virtualdrive!" ( echo %~d0 is a CD-ROM Drive set REMOTE=1 set dstpath="%TMPDIR%\localhpsum" goto :run ) ) rem check whether it is Remote/Network mapped Drive set remotedrive=%~d0 - Remote/Network Drive FOR /F "tokens=*" %%A IN ('"fsutil fsinfo drivetype"" "%~d0""') do ( if /i "%%A"=="!remotedrive!" ( echo %~d0 is a Remote/Network Drive set REMOTE=1 set dstpath="%TMPDIR%\localhpsum" goto :run ) ) IF "!HPSUM_ROOT:~1,2!"=="\\" ( echo %HPSUM_ROOT is a remote UNC path set REMOTE=1 set dstpath="%TMPDIR%\localhpsum" ) ELSE ( for /f "skip=6 tokens=2" %%d in ('net use') do ( if /i "!HPSUM_ROOT:~1,2!"=="%%d" ( echo !HPSUM_ROOT! is a Network Mapped Drive set REMOTE=1 set dstpath="%TMPDIR%\localhpsum" goto :run ) ) ) :run set newcmdcmdline=%cmdcmdline:"=-% set withincmd=1 echo %newcmdcmdline% | find /i "cmd /c --%~dpf0%-" if %errorlevel% EQU 0 set withincmd=0 rem if %withincmd% EQU 0 echo This batch-file: %~dpf0 was executed directly (from Windows Explorer, ...). rem if %withincmd% EQU 1 echo This batch-file: %~dpf0 was executed from within a Command Prompt rem Select 32-bit or 64-bit SET HostIs64Bit=%ProgramFiles(x86)% IF "%HostIs64Bit%"=="" ( set HPSUM_ARCH=x86 ) ELSE ( set HPSUM_ARCH=x64 ) rem Check if any of the following switches were passed as arguments. rem They will not yet require a copy of the HPSUM Files if remote. rem check for: /v, /version (version information) rem check for: /h, /?, /help (help) rem check for silent as it is a different mode for HPSUM rem check for: /s, /silent rem Initialize SET INPUTFILEPATH= SET USELOCATION=0 SET LEGACYMODE=0 SET ERRORCODE=0 :loop IF NOT "%~1"=="" ( rem Get if silent flag is set. Treat it exactly like express_install. IF "%~1"=="/s" SET LEGACYMODE=1 IF "%~1"=="/silent" SET LEGACYMODE=1 rem Get if express_install flag is set. Treat it exactly like silent mode. IF "%~1"=="/express_install" SET LEGACYMODE=1 rem Handle working directory IF "%~1"=="/use_location" ( SET USELOCATION=1 SHIFT ) rem Handle input file IF "%~1"=="/inputfile" ( SET INPUTFILEPATH="%~2" SHIFT ) rem handle logdir IF "%~1"=="/logdir" ( SHIFT ) rem Handle version IF "%~1"=="/v" SET VERSION=1 IF "%~1"=="/version" SET VERSION=1 rem Handle help IF "%~1"=="/h" SET HELP=1 IF "%~1"=="/help" SET HELP=1 IF "%~1"=="/?" SET HELP=1 SHIFT GOTO :loop ) rem If help or version commands were detected, then skip the copy and execute HPSUM IF %REMOTE% EQU 0 GOTO :runhpsum rem Check if there's an existing hpsum service running.. tasklist /FI "IMAGENAME eq hpsum_service_%HPSUM_ARCH%.exe" 2>NUL | find /I /N "hpsum_service_%HPSUM_ARCH%.exe" >NUL IF %ERRORLEVEL% NEQ 0 ( GOTO :copyfiles ) ELSE ( SET SERVICERUNNING=1 IF %LEGACYMODE% EQU 0 ( GOTO :copyfiles ) ELSE ( rem ONLY if a silent switch is detected, do not allow running of hpsum again. rem Otherwise, let it through as it could be interactive commands. echo An existing HP SUM session is detected. set ERRORCODE=-4 goto :WrapUp rem IF %withincmd% EQU 0 ( rem call :delay rem ) rem GOTO :Exit ) ) :copyfiles SET HPSUM_VERSION_EXIST=0 IF EXIST %HPSUM_ROOT%hpsum*_b*.txt ( FOR /F "delims=" %%a IN ('dir /b !HPSUM_ROOT!\"hpsum*_b*.txt"') DO SET HPSUM_VERSION_FILE=!params!%%a IF NOT "!HPSUM_VERSION_FILE!"=="" ( IF EXIST !dstpath!\!HPSUM_VERSION_FILE! ( SET HPSUM_VERSION_EXIST=1 ) ELSE ( rd /s /q !dstpath! 2> NUL ) ) ) IF %HPSUM_VERSION_EXIST% EQU 0 ( echo Copying HP SUM files from !HPSUM_ROOT! to !dstpath! IF NOT EXIST !dstpath! ( md !dstpath! rem Check if the folder is now present. IF NOT EXIST !dstpath! ( echo Could not create the temporary directory !dstpath! SET ERRORCODE=-4 goto :WrapUp ) ) xcopy /s /y /i /q "!HPSUM_ROOT!\%HPSUM_ARCH%" "!dstpath!\%HPSUM_ARCH%" 2>NUL IF !ERRORLEVEL! NEQ 0 ( IF !SERVICERUNNING! EQU 0 ( SET ERRORCODE=-4 goto :WrapUp ) ) IF !VERSION! NEQ 0 ( goto :runhpsum ) xcopy /s /y /i /q "!HPSUM_ROOT!\assets" "!dstpath!\assets" IF !ERRORLEVEL! NEQ 0 ( SET ERRORCODE=-4 goto :WrapUp ) IF !HELP! NEQ 0 ( goto :runhpsum ) xcopy /s /y /i /q "!HPSUM_ROOT!\cygwin" "!dstpath!\cygwin" IF !ERRORLEVEL! NEQ 0 ( SET ERRORCODE=-4 goto :WrapUp ) xcopy /y /i /q "!HPSUM_ROOT!masterdependency.xml" "!dstpath!\" IF !ERRORLEVEL! NEQ 0 ( SET ERRORCODE=-4 goto :WrapUp ) xcopy /y /i /q "!HPSUM_ROOT!platformdependency.xml" "!dstpath!\" IF !ERRORLEVEL! NEQ 0 ( SET ERRORCODE=-4 goto :WrapUp ) xcopy /y /i /q "!HPSUM_ROOT!gatherlogs.bat" "!dstpath!\" IF !ERRORLEVEL! NEQ 0 ( SET ERRORCODE=-4 goto :WrapUp ) IF NOT "%HPSUM_VERSION_FILE%"=="" ( xcopy /y /i /q "!HPSUM_ROOT!!HPSUM_VERSION_FILE!" "!dstpath!\" ) IF EXIST "%INPUTFILEPATH%" xcopy /y /i /q "%INPUTFILEPATH%" "!dstpath!\" IF !ERRORLEVEL! NEQ 0 ( SET ERRORCODE=-4 goto :WrapUp ) ) rem If working directory is not set, and it is a read-only then append use_location with the mount point path IF %LEGACYMODE% EQU 1 ( IF %USELOCATION% NEQ 1 ( SET "HPSUM_CMD_ARGS=!HPSUM_CMD_ARGS! /use_location !HPSUM_ROOT!" ) ) :runhpsum set HPSUM_BIN="!dstpath!\%HPSUM_ARCH%\hpsum_bin_%HPSUM_ARCH%.exe" IF NOT EXIST %HPSUM_BIN% ( @echo Unable to locate %HPSUM_BIN% IF %withincmd% EQU 0 ( call :delay ) set ERRORCODE=-4 goto :Exit ) %HPSUM_BIN% !HPSUM_CMD_ARGS! set ERRORCODE=%ERRORLEVEL% rem the acutal binary should have displayed an error rem message. We still want to delay to allow rem people who started by clicking on the icon rem a chance to see the message :WrapUp IF %ERRORCODE% NEQ 0 ( if %withincmd% EQU 0 ( call :delay ) goto :Exit ) goto :Exit :delay where ping > nul 2>&1 IF %ERRORLEVEL% NEQ 0 ( pause ) else ( @echo Pausing for 10 seconds ... ping -n 11 127.0.0.1 > nul ) goto :EOF :Exit IF %REMOTE% EQU 1 ( IF "%HPSUM_REMOVE_TEMP_FILES%"=="true" ( echo HPSUM_REMOVE_TEMP_FILES set true, removing hpsum files rd /s /q !dstpath! 2> NUL ) ) exit /b %ERRORCODE%