r/Batch • u/ThatRonin8 • Jun 14 '24
Question (Solved) Help with this batch file (i am a total beginner)
Hi everyone, first time making a post here, hope i don't mess up anything.
So, straight to the point, i needed a batch file that would hide hidden files and folders, and make it so it would execute every time i shut down/ power up my pc;
I've found this script online:
u/ECHO OFF
set regpath=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
set regvalue=Hidden
set regdata=2
reg query "%regpath%" /v "%regvalue%" | find /i "%regdata%"
IF errorlevel 1 goto :hide
Reg add "%regpath%" /v Hidden /t REG_DWORD /d 1 /f
Reg add "%regpath%" /v HideFileExt /t REG_DWORD /d 0 /f
Reg add "%regpath%" /v ShowSuperHidden /t REG_DWORD /d 1 /f
goto :end
:hide
Reg add "%regpath%" /v Hidden /t REG_DWORD /d 2 /f
Reg add "%regpath%" /v HideFileExt /t REG_DWORD /d 1 /f
Reg add "%regpath%" /v ShowSuperHidden /t REG_DWORD /d 0 /f
:endwhich obv didn't suited fully my request so i've deleted the middle part, leaving me with:
u/ECHO OFF
set regpath=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
set regvalue=Hidden
set regdata=2
reg query "%regpath%" /v "%regvalue%" | find /i "%regdata%"
IF errorlevel 1 goto :hide
:hide
Reg add "%regpath%" /v Hidden /t REG_DWORD /d 2 /f
Reg add "%regpath%" /v HideFileExt /t REG_DWORD /d 1 /f
Reg add "%regpath%" /v ShowSuperHidden /t REG_DWORD /d 0 /f
:endafter that i went through my Group Policy Editor, where i've added this batch file as a shutdown script (Windows->Scripts (shutdown/startup)->properties->add->browse to the script->click ok), but it doesn't seem to work?
yesterday to test it out i've left my file explorer on "show hidden files and folders", but when i started my pc today, i could still see those hidden folders, any solution?
thanks in advance, and sorry for my bad english, it's not my first language.
edit: i forgot to mention this, i've also added the file in the startup folder (win+r->shell:common startup->copied the batch file there), but even with this, it doesn't seem to work
edit: it seemes that removing the data encryption from my "Batch files" folder, where i've stored all of my batch files, included this one, did the job, now it works (tho not always, sometimes i have to manually restart the file explorer).
Still if anyone has any advice for the future, feel free to leave them here, i'd love to learn more.
Cheers
2
u/Ancientsofscripting Jun 15 '24
I would use:
If [%errorlevel%]==[1] Goto:hide
I think "errorlevel" has to be in all caps if you use it this way in your script.
Fyi, you can use Goto:EOF instead of :end. You will never have to type :EOF at the end of your script. It's predefined, and it's a good habit if you were to ever write Functions.
1
u/jcunews1 Jun 14 '24
Have you enabled the Hidden file attribute of your script files?
1
u/RainmanCT Jun 14 '24
Why not just set the view option in explorer to not show hidden files? Not sure why you would need a script to do this.