Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

click - Running a batch script by right clicking any file

The idea is to right click any file and then select "backup" in a drop down that just copies the file and adds a date time to the end of its name, then possibly moves that copy to another drive.

I would like a method of running a batch script by right clicking on a file and either passing that in as an argument (without typing it in), or somehow knowing that file is the one that should be used in the script.

Mainly for windows XP, I need it to be native as many site computers I work on do not belong to us and I don't want to copy over more files than necessary or rely on anything more than the standard commands available (two thirds of the machines don't have powershell ect)

I know how you can change file options to open a cmd at a specific folder location(below), and I cold probably change this to work for 1 specific file type, but I don't want to add a key for each type of file on the machine.

[HKEY_CLASSES_ROOTFoldershell1.batcommand] @="c:windowssystem32cmd.exe "%1""

From another site one work around that nearly solves this for me

jvierra - "Windows has always had that ability without changing the registry.

Place a bat or VBS file on your desktop. Drag and drop a file on the bat icon. The bat will receive the file name of the dropped file as %1 and vbscript will receive it as WScript.Arguments(0).

Try it. It works quite well. The bat or script can do anything with the file from that point."

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...