Running a batch script by right clicking any file

丶灬走出姿态 提交于 2019-11-28 21:40:56

you can add your bat to the "Send To" menu. See http://support.microsoft.com/kb/310270

In brief, just copy your .bat file into the user SendTo folder.

COPY MYBACKUP.BAT "%USERPROFILE%\SendTo"

the user invokes your bat selecting the option of the "Send To" menu item.

for more sophisticated parametrization, like changing the text displayed in the menu, or the icon... you may create a link to your .BAT and place the link in the SendTo folder instead of the .bat itself

COPY "My very special backup.lnk" "%USERPROFILE%\SendTo"

You may first run a quick test. Create a BAT file with this content, and copy it over Sendto folder.

@echo off
echo Current Directory is %cd%
echo Current batch run is %0 %~dpnx0
echo Subject is %1 %~dpnx1
pause  

Edit: following some of the commments, I have corrected the SendTo folder specification in the COPY command, by adding the required quotes; and I have appended an test example, and corrected the %~dpnx syntax

@PA example (copied right below for easy viewing) is off by a hair.

@echo off
echo Current Directory is %cd%
echo Current batch run is %0 %dpnx0
echo Subject is %1 %dpnx1
pause  

I don't have enough reputation to respond to @PA. You forgot to include the ~ in the variable. This Q & A helped me a lot so I hope this helps someone else out. Thanks @daniel and @PA

Corrected daniel test example below

@echo off
echo Current Directory is %cd%
echo Current batch run is %0 %~dpnx0
echo Subject is %1 %~dpnx1
pause

If you want to just echo the name of the file without the path then you would use %~n1

example:

echo Subject is %~n1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!