通过右键单击任何文件来运行批处理脚本 [英] Running a batch script by right clicking any file

查看:279
本文介绍了通过右键单击任何文件来运行批处理脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个想法是右键单击任何文件,然后在下拉菜单中选择备份",该菜单仅复制该文件并在其名称末尾添加一个日期时间,然后可能将该副本移动到另一个驱动器.

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.

主要用于Windows XP,我需要它是本机的,因为我正在使用的许多站点计算机都不属于我们,并且我不想复制超出必要数量的文件,也不希望依赖除可用的标准命令以外的任何内容(三分之二的机器没有Powershell等)

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)

我知道如何更改文件选项以在特定文件夹位置(如下)打开cmd,并且我很可能将其更改为适用于1种特定文件类型,但是我不想为每个文件添加密钥机器上文件的类型.

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_ROOT \ Folder \ shell \ 1.bat \ command] @ ="c:\ windows \ system32 \ cmd.exe \"%1 \"

[HKEY_CLASSES_ROOT\Folder\shell\1.bat\command] @="c:\windows\system32\cmd.exe \"%1\""

从另一个站点进行的一项变通为我几乎解决了这个问题

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

jvierra-"Windows一直具有该功能,而无需更改注册表.

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

在您的桌面上放置一个bat或VBS文件.将文件拖放到蝙蝠图标上.蝙蝠将收到已删除文件的文件名%1,而vbscript将收到它的文件名WScript.Arguments(0).

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."

推荐答案

,您可以将蝙蝠添加到发送到"菜单中.请参阅 http://support.microsoft.com/kb/310270

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

简而言之,只需将.bat文件复制到用户SendTo文件夹中即可.

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.

要进行更复杂的参数化,例如更改菜单中显示的文本或图标...,您可以创建指向.BAT的链接,并将该链接放置在SendTo文件夹中,而不是.bat本身

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"

您可以先运行快速测试.使用此内容创建一个BAT文件,然后将其复制到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  


编辑:根据一些评论,我通过添加所需的引号来更正了COPY命令中的SendTo文件夹规范.并且我附加了一个测试示例,并更正了%~dpnx语法


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

这篇关于通过右键单击任何文件来运行批处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆