hackoofr

Show-Hide_Desktop_Icons.bat

Dec 25th, 2022 (edited)
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.71 KB | Source Code | 0 0
  1. @echo off
  2. Title Show Or Hide Desktop Icons And Show Or Hide Seconds In System Clock
  3. Color 9E & Mode 82,12 & SetLocal EnableDelayedExpansion
  4. Call:CreateShortcut
  5. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  6. :: Automatically check & and start the batch file with admin rights
  7. (Net session >nul 2>&1)||(PowerShell start """%userprofile%\Desktop\%~n0.lnk""" -verb RunAs & Exit /B)
  8. ::--------------------------------------------------------------------------
  9. Set "Key=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
  10. ::--------------------------------------------------------------------------
  11. :GetInfo
  12. @REM Get Opened Folders with PowerShell code in a batch file
  13. Set PSCommand="@((New-Object -com shell.application).Windows()).Document.Folder | ForEach { $_.Self.Path }"
  14. REM  Populate the array with existent and opened folders
  15. SetLocal EnableDelayedExpansion
  16. Set /a Count=0
  17. for /f "delims=" %%a in ('Powershell -C %PSCommand%') do (
  18.     Set /a Count+=1
  19.     Set "Folder[!Count!]=%%a"
  20. )
  21. ::===========================================================================
  22. :menuLOOP
  23. ::===========================================================================
  24. echo(
  25. echo(
  26. echo(       ***************************** Menu ******************************
  27. echo(
  28. @for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do (
  29. echo(                 %%A  %%B)
  30. echo(
  31. echo(       *****************************************************************
  32. echo( &Set /p Selection=Make a Selection or hit ENTER to quit: || Goto :EOF
  33. echo( & Call:menu_[%Selection%]
  34. GOTO:menuLOOP
  35. ::===========================================================================
  36. ::---------------------------------------------------------------------------------------------------
  37. :menu_[1] Show Seconds In SystemClock
  38. reg Add "%Key%" /V ShowSecondsInSystemClock /T REG_DWORD /D 1 /F 1>NUL
  39. Call:Restart_Explorer
  40. @rem Restore all closed folders
  41. @for /L %%i in (1,1,%Count%) do Start /MAX Explorer "!Folder[%%i]!"
  42. Exit /B
  43. ::---------------------------------------------------------------------------------------------------
  44. :menu_[2] Hide Seconds In SystemClock
  45. reg Add "%Key%" /V ShowSecondsInSystemClock /T REG_DWORD /D 0 /F 1>NUL
  46. Call:Restart_Explorer
  47. @rem Restore all closed folders
  48. @for /L %%i in (1,1,%Count%) do Start /MAX Explorer "!Folder[%%i]!"
  49. Exit /B
  50. ::---------------------------------------------------------------------------------------------------
  51. :menu_[3] Hide Desktop Icons
  52. reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDesktop /t REG_DWORD /d 1 /f 2>nul
  53. Call:Restart_Explorer
  54. @rem Restore all closed folders
  55. @for /L %%i in (1,1,%Count%) do Start /MAX Explorer "!Folder[%%i]!"
  56. Exit /B
  57. ::---------------------------------------------------------------------------------------------------
  58. :menu_[4] Show Desktop Icons
  59. reg delete HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDesktop /f 2>nul
  60. Call:Restart_Explorer
  61. @rem Restore all closed folders
  62. @for /L %%i in (1,1,%Count%) do Start /MAX Explorer "!Folder[%%i]!"
  63. Exit /B
  64. ::---------------------------------------------------------------------------------------------------
  65. :Restart_Explorer
  66. Powershell -C "gps explorer | spps"
  67. Exit /B
  68. ::---------------------------------------------------------------------------------------------------
  69. :CreateShortcut
  70. Powershell ^
  71. "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\%~n0.lnk'); ^
  72. $s.TargetPath='%~f0'; ^
  73. $s.WorkingDirectory='%~dp0'; ^
  74. $s.IconLocation='colorcpl.exe,0'; ^
  75. $s.HotKey='CTRL+ALT+I'; ^
  76. $s.Save()"
  77. Exit /B
  78. ::---------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment