Create a shortcut to your batch file in the shell:sendto
folder and change its properties as follows:
- right click -> ˙Properties˙ ->
Shortcut
tab; - Target ->
cmd /C "D:\bat\SU\931003.bat"
; Advanced
button -> Run as administrator.
Note the first echo "%CD%"
in next code snippet shows the initial working directory of your script ("C:\Windows\system32"
if launched by SendTo
feature):
==>type D:\bat\SU\931003.bat
@echo off
echo initial working directory "%CD%"
pushd "%~dp1"
echo current working directory "%CD%"
echo paramer #1 supplied "%~1"
echo all paramers %*
net session
pause
Sample output
initial working directory "C:\Windows\system32"
current working directory "D:\bat\1 & 2"
paramer #1 supplied "D:\bat\1 & 2\931003 test.txt"
all paramers "D:\bat\1 & 2\931003 test.txt" "D:\bat\1 & 2\batchfile.bat"
There are no entries in the list.
Press any key to continue . . .
Above output shows:
- works with slightly unusual path and file name containing not only spaces but even
&
ampersand character... - works as administrator as otherwise the
net session
command returnsSystem error 5 has occurred
andAccess is denied
error messages.