How to add batch script to context menu of multipl

2019-09-22 02:32发布

问题:

I've been trying to setup a batch script that can be run from the context menu inside a folder. The purpose of the batch script is to populate the folder with a predetermined folder structure.

This will need to be replicated on multiple computers(Windows 7-10), so my idea was to have a network share with two batch files and one .reg file. One of the batch files labeled "install.cmd" would copy the other batch file labeled "Subfolders.cmd" to a folder on the C drive, and run the .reg file to install a shortcut on the context menu to the "Subfolders.cmd" batch file.

I have created the "Subfolders.cmd" batch file and it works, but it has to be run from inside the folder I want the folder structure setup in. I would appreciate any help on how to create the "install.cmd" batch script that would create a folder on the C drive, copy the "Subfolders.cmd" script into it, and run the .reg file to create the item in the context menu that would allow the "Subfolders.cmd" batch script to be run in selected folder.

I'd appreciate any examples and/or suggestions of more efficient ways of doing this. Thanks!

Update: As requested, I have posted the code that generates the subfolders inside an opened folder. It's pretty simple.

md "Folder1" "Folder1/Sub1A" "Folder1/Sub1B" "Folder2" "Folder2/Sub2A" "Folder2/Sub2B"

回答1:

There is no need for all this copying.

"\\computername\sharename\folder\file.bat"

Will run a batch file stored on another computer.

Ditto the reg command

regedit /s "\\computername\sharename\folder\file.reg"

You can do the above with the older mapped drives as well as UNC.

You need to show your second script so we can see why it NEEDS to be in the folder.

EDIT

You need to specify full paths.

To get the starting folder use %V in the registry command. So (and lets get rid of the reg file) (add your bat instead of echo)

reg add "HKCR\Directory\Background\Shell\Test Command\command" /ve /t REG_EXPAND_SZ /d "cmd /k echo ""%V"""

In your batch use %1 to get the starting folder, and tilde (%~1) to remove quotes (see call /? for documentation). (remember create folders from the lowest level as higer levels get made automatically).

md "%~1\folder1\folder2"