Longpath

Description

The script bellow is used to execute a program or installer when the file path is to long.

this script will work on a network share OR a local path
and automatic detect a free drive letter

Changelog

Version 1.0
Initial version

Version 1.1
NEW: Add support for paramaters
FIX: #001001 Script shows a red screen when there is no error

Version 1.2
NEW: add support for local path

Known issue’s

#001002
Symptoms: the user is presented with a windows error when the device has a empty cardreader or cd/dvd station
Workaround: click continue

Errorlevel

0
Problem:  the script finished without any error

001001
Problem: Share not found
Solution: Correct the Share path

001002
Problem: can not connect to the drive
Solution: check if the sharename is correct and you have the right permissions

001002
Problem: can not connect to the local folder
Solution: check if the sharename is correct and you have the right permissions

002003
Problem: Executable or script not found
Solution: make sure the name of the executable or script is correct
Make sure you don’t place parameters in the bin variable

Other errorlevels are pass trough from the executable or script

The Script

 

REM disable echo
@echo off
cls
REM #####################################################
REM # Title : Longpath #
REM # Subject : prevent issue’s with long file path #
REM # Author : Mark de Bruin #
REM # Website : tools.fnetonline.nl/script/001 #
REM # Date : 23-05-2016 #
REM #####################################################

REM #################### Settings #######################

REM ## Version ##
set Ver=1.2

REM ## filepath ##
REM place here the network path to the parrent folder this can also be a local path
REM this vallue can have spaces and can NOT contain quote’s “”
set Share=\\server\share\long\path

REM ## Bin ##
REM place here the executable
REM this can also be another script
Set Bin=a_file_or_script.bat

REM set the parameter(leave empty for none)
set Par=

REM ## silent ##
REM let the script continue on error y/n
set sil=N

REM ################ End of settings ####################
REM ######### do not change anything bellow #############

REM #################### script #######################
Rem check for the location (network or local)
set location=error
if “%share:~1,1%” == “\” set location=share
if “%share:~1,1%” == “:” set location=local
if %location% == error (
set exitcode=001001
set errormesage=config: Wrong Share parameter
goto error
)

for %%p in (a b g h i j k l m n o p q r s t u v w x y z) do if not exist %%p:\nul set drive=%%p
echo The script will use derive %drive%:

goto %location%
:share
net use %drive%: “%Share%” /persistent:no
if not %errorlevel% == 0 (
set exitcode=001002
set errormesage=%location% %drive%: failed
goto error
)
goto next
:local

subst %drive%: “%Share%”
if not %errorlevel% == 0 (
set exitcode=001003
set errormesage=%location% %drive%: failed
goto error
)
goto next

:next
%drive%:

if /i NOT exist “%Bin%” (
set errormesage=Bin: File %Bin% not found
set exitcode=002003
goto error
)

start /wait “Running” “%Bin%” %Par%
set exitcode=%errorlevel%
if NOT “%exitcode%” == “0” goto error
color 0a
if /i NOT “%sil%” == “y” pause
if %location% == share net use %drive% /d
if %location% == local subst %drive% /d
exit 0

:error

cls
color 0c
echo %exitcode% %errormesage%
echo for more information http://tools.fnetonline.nl/script/001
if /i NOT “%sil%” == “y” pause
if %location% == share net use %drive% /d
if %location% == local subst %drive% /d
exit %exitcode%

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *