Skip to main content
added 681 characters in body
Source Link
JosefZ
  • 13.4k
  • 5
  • 40
  • 72

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

batch shortcut in the SendTo folder (to be run as administrator)

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 returns System error 5 has occurred and Access is denied error messages.

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 "%~1"
pause

batch shortcut in the SendTo folder (to be run as administrator)

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

batch shortcut in the SendTo folder (to be run as administrator)

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 returns System error 5 has occurred and Access is denied error messages.
added 119 characters in body
Source Link
JosefZ
  • 13.4k
  • 5
  • 40
  • 72

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 "%~1"
pause

batch shortcut in the SendTo folder (to be run as administrator)

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 "%~1"
pause

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 "%~1"
pause

batch shortcut in the SendTo folder (to be run as administrator)

Source Link
JosefZ
  • 13.4k
  • 5
  • 40
  • 72

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 "%~1"
pause