Using batch parsing techniques, I have scripted RemoteScript.bat to determine if your script was executed from a remote network path.

The syntax for using RemoteScript.bat is:

call RemoteScript FullyQualifiedScriptName YesNo

Where FullyQualifiedScriptName should literally be %~F0, and YesNo is a call directed environment variable that will contain a Y if the your script was executed from a remote network path, or an N if it was executed from a local path.

NOTE: A UNC path that points to the local computer is considered local, as are net use and subst drives that point to the local computer.

RemoteScript.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax call RemoteScript ScriptPath YesNo&exit /b 1
if not exist %~F1 @echo Syntax call RemoteScript ScriptPath YesNo - ScriptPath does NOT exist.&exit /b 2
set Rmt=N
set Drv=%~D1
if "%Drv%" NEQ "\\" goto callq
set Rmt=Y
:: Test if UNC path is local
for /f "Tokens=*" %%r in ('@echo %~F1^|Findstr /i /l /c:"\\%computername%"') do set Rmt=N
goto Finish
call :quiet>nul 2>&1
endlocal&set %2=%Rmt%
exit /b 0
<font size="1">for /f "Tokens=*" %%r in ('net use %Drv%^|Findstr /I /L /C:"Remote name"^|Findstr /i /l /v /c:"\\%computername%"') do set Rmt=Y&goto quietend
for /f "Tokens=*" %%r in ('subst ^|Findstr /i /l /b /c:"%Drv%"^|Findstr /i /l /c:UNC\^|Findstr /i /l /v /c:"\\%computername%"') do set Rmt=Y</font>