If you want something you can do from the context menu, here's one way that might save you some time if you're trying to do this a lot:
Create a batch file RemoveSysAttrib.bat
@echo off
attrib -s "%1%"
Then follow this guide for adding a custom app to the context menu: How to Add Any Application to the Windows Desktop Right-Click Menu
You could then have a menu item called "Remove system attribute" which does just that, using your batch file. This way, you could also create a script to add the attribute back. Might be a bit fiddly getting it to work for multiple file selections, but with a bit of luck it will launch your file once for each selected item. You'll want to test this with:
@echo off
echo %1%
pause
If it supplies the file names as attribute 1, 2, 3, etc you'll have to loop over all parameters. If more than one parameter is supplied, you could invoke your script recursively like this:
if NOT "%2%"=="" (
for %%A in (%*) do (
RemoveSysAttrib.bat "%%A"
)
) else (
attrib -s "%1%"
)
Hope that helps =)
In response to Synetech's comments:
When you use attrib
, it won’t change the H
or S
settings if the other
is set (it will say not resetting XXXX file). You would need to strip
(or set) both, then change the one that you did not want to modify
back to what it was before.
I extended the script to check the 'H' attribute reported by Windows 7's attrib
command. To make it more generic, you would need to check more substring positions, as I have a hunch that it's different in other versions. I don't have other versions of Windows handy right now, so I can't check.
@echo off
setlocal enabledelayedexpansion
:: Check if file is hidden - works on Windows 7
set hidden=0
for /f "delims=" %%A in ('attrib "%1%"') do (
set attr=%%A
if "!attr:~4,1!"=="H" set hidden=1
)
:: If file is hidden, remove both attributes, then hide again.
if %hidden%==1 (
attrib -S -H "%1%"
attrib +H "%1%"
) else (
attrib -S "%1%"
)
endlocal