Open a command prompt, run call /?
and read the output help carefully and completely. It explains how batch file arguments can be referenced from within a batch file. Argument 0 is always the batch file itself.
The batch file for your purpose could be coded as:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "FileName=%~1"
if not defined FileName goto PrintHelp
set "FileName=%FileName:"=%"
if not defined FileName goto PrintHelp
if "%FileName%" == "/?" goto PrintHelp
set "FileName=%FileName:/=\%"
if not exist "%FileName%" (
echo ERROR: File not found: "%FileName%"
echo(
pause
goto EndBatch
)
set "FileName=%FileName:\=/%"
if not "%FileName:~0,1%" == "/" set "FileName=///%FileName%"
start "" shell:AppsFolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge "file:%FileName%"
goto EndBatch
:PrintHelp
echo INFO: %~nx0 must be called with name of a file to open in Microsoft Edge.
echo(
pause
:EndBatch
endlocal
I do not really understand why a batch file is needed at all to open PDF files in Microsoft Edge. It would be also possible to simply associate the file extension .pdf
with Microsoft Edge to get PDF files opened by default with Microsoft Edge.
The following command line can be executed in a command prompt window to get displayed which application is associated currently with file extension .pdf
and which command is used to open a PDF file with %1
being the placeholder for the file name:
for /F "skip=1 tokens=2*" %I in ('%SystemRoot%\System32\reg.exe query HKEY_CLASSES_ROOT\.pdf /ve 2^>nul') do %SystemRoot%\System32\reg.exe query "HKEY_CLASSES_ROOT\%J\Shell\Open\Command" /ve
To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
echo /?
endlocal /?
goto /?
if /?
pause /?
set /?
setlocal /?
start /?
See also the Wikipedia article about file URI scheme. It would be necessary to percent encode the file name for a 100% correct file URL, but Microsoft Edge supports also not correct encoded file URLs containing for example a space character instead of %20
or the umlaut ä
instead of %c3%a4
.