@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=%* setlocal EnableDelayedExpansion SET HPSUM_ROOT=%~dp0 rem remove trailing back slash IF "!HPSUM_ROOT:~-1!"=="\" SET HPSUM_ROOT=!HPSUM_ROOT:~0,-1! SET dstpath=!HPSUM_ROOT! SET REMOTE=0 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=%temp%\localhpsum goto :run ) ) IF "!HPSUM_ROOT:~0,2!"=="\\" ( echo %HPSUM_ROOT is a remote UNC path set REMOTE=1 set dstpath=%temp%\localhpsum ) ELSE ( for /f "skip=6 tokens=2" %%d in ('net use') do ( if /i "!HPSUM_ROOT:~0,2!"=="%%d" ( echo !HPSUM_ROOT! is a Network Mapped Drive set REMOTE=1 set dstpath=%temp%\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 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 defined HELP GOTO :runhpsum IF defined VERSION GOTO :runhpsum 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 ( echo Copying HP SUM files from !HPSUM_ROOT! to !dstpath! IF NOT EXIST !dstpath! ( md !dstpath! IF %ERRORLEVEL% NEQ 0 echo Problem Creating !dstpath!, Return code %ERRORLEVEL% ) xcopy /s /y /i /q "!HPSUM_ROOT!\%HPSUM_ARCH%" "!dstpath!\%HPSUM_ARCH%" IF %ERRORLEVEL% NEQ 0 ( SET ERRORCODE=-4 ) xcopy /s /y /i /q "!HPSUM_ROOT!\assets" "!dstpath!\assets" IF %ERRORLEVEL% NEQ 0 ( SET ERRORCODE=-4 ) xcopy /s /y /i /q "!HPSUM_ROOT!\cygwin" "!dstpath!\cygwin" IF %ERRORLEVEL% NEQ 0 ( SET ERRORCODE=-4 ) xcopy /y /i /q "!HPSUM_ROOT!\masterdependency.xml" "!dstpath!\" IF %ERRORLEVEL% NEQ 0 ( SET ERRORCODE=-4 ) xcopy /y /i /q "!HPSUM_ROOT!\nic_pciid.xml" "!dstpath!\" IF %ERRORLEVEL% NEQ 0 ( SET ERRORCODE=-4 ) IF EXIST "%INPUTFILEPATH%" xcopy /y /i /q "%INPUTFILEPATH%" "!dstpath!\" rem Check ERRORCODE. if not 0, then one or more of the copy commands failed. rem IF !ERRORCODE! NEQ 0 ( rem echo One or more files/folders failed to copy rem IF %withincmd% EQU 0 ( rem call :delay rem ) rem GOTO :Exit rem ) 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!"" ) ) ) ELSE ( IF %LEGACYMODE% EQU 1 ( 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. IF %withincmd% EQU 0 ( call :delay ) GOTO :Exit ) ) :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 ) echo %HPSUM_BIN% !HPSUM_CMD_ARGS! %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 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 exit /b %ERRORCODE%