0

I'm looking for a way to apply a cmd or powershell script to a certain file by right clicking the file in windows explorer and choosing "Apply script XYZ".

A use case would be to make a file write protected, so my batch file would contain:

attrib +r %filename%

where %filename% is the name of the file I right clicked on in explorer.

Single file would do the trick for now, but I would be interested in applying it to multiple files (by selecting multiple files in a folder) and whole folders (by selecting the folder) as well.

The solution should work for Windows 10 and, if possible, for UNC-paths and Windows 7 as well.

EDIT: So far I managed to get everything done expect for the UNC-Paths, this example works for files (using this source and this source):

Registry Entry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\SomeName]
@="NameOfTheMenueItem"
"icon"="someicon.ico"

[HKEY_CLASSES_ROOT\*\shell\SomeName\command]
@="\"X:\\folder\\batchfile.cmd\" \"%1\""

Batch File:

set filepath=%1
attrib +r %filepath%

Batch File (for folders):

set folderpath=%1
attrib +r %folderpath%\*.*

Remaining Problems:

  • I need it to work for UNC-Paths
  • return the folderpath to the batchfile without "" in order to change it to "X:\folderpath\*.*" (at the moment I get "X:\folderpath" as a return value, although just adding \*.* works the result "X:\folderpath"\*.* does not look very good, not sure if there will be any problems at some point)
  • create a recursive write protect for all files and sub-folders for a chosen folder
Albin
  • 9,307
  • 11
  • 50
  • 89
  • just found some basic instruction [here](https://superuser.com/questions/444726/windows-how-to-add-batch-script-action-to-right-click-menu). So I should be able to do it for a single file. Still looking for a solution for UNC-paths, for multiple files and for whole folders and the icon problem. – Albin Oct 20 '19 at 15:03
  • This answer does both files and folders ... https://superuser.com/a/1070883/337631 – DavidPostill Oct 20 '19 at 16:27
  • @DrMoishePippik I linked to that question myself in my first comment and explained why it's not a duplicate, David linked to it as well. – Albin Oct 20 '19 at 20:15
  • FYI: You don't write-protect a folder by setting its read-only attribute. – Keith Miller Oct 20 '19 at 20:29
  • @KeithMiller thanks, that was s.th. left over from a previous version of the question. I edited the question. – Albin Oct 20 '19 at 20:32
  • Are you saying that you can't provide a UNC path to your script or that items navigated to via UNC don't have the context menu item? – Keith Miller Oct 20 '19 at 21:24
  • @KeithMiller honstly I did not check it myself yet. my [source](https://superuser.com/a/1070883/201818) says it will not work for UNC paths – Albin Oct 20 '19 at 21:27

0 Answers0