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