programing

Powershell을 통해 Windows 탐색기 폴더 옵션 구성

itmemos 2023. 7. 31. 21:06
반응형

Powershell을 통해 Windows 탐색기 폴더 옵션 구성

Windows 탐색기의 폴더 옵션 대화 상자에서 Powershell을 통해 몇 가지 옵션을 구성하는 방법을 찾고 있습니다.

옵션은 다음과 같습니다.

  • 숨겨진 파일, 폴더 및 드라이브 표시를 선택합니다.
  • 알려진 파일 형식에 대한 확장명 숨기기 선택 취소
  • "보호된 운영 체제 파일 숨기기(권장)"의 선택을 취소합니다.

키스의 대답은 처음부터 제게 효과가 없었습니다.레지스트리 값을 수정하는 데 필요한 것은 ShowSuperHidden뿐입니다.폴더 설정에서 보기 탭을 열자마자 숨김(숨김 파일 표시...)과 파일 확장명 숨기기(숨김)가 모두 이전 값으로 되돌아갔습니다.

시행착오 끝에 찾은 해결책이 있습니다(탐색자).exe가 자동으로 다시 시작됨):

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key Hidden 1
Set-ItemProperty $key HideFileExt 0
Set-ItemProperty $key ShowSuperHidden 1
Stop-Process -processname explorer

윈도우즈 서버 2008 R2 및 윈도우즈 7에서 테스트했습니다.

샘플 윈도우즈 레지스트리(문서) 스크립트:

Windows Registry Editor Version 5.00

[hkey_current_user\software\microsoft\windows\currentversion\explorer\advanced]

;hide empty drives [uncheck]
"hidedriveswithnomedia"=dword:00000000

;hide extensions for known file types [uncheck]
"hidefileext"=dword:00000000

;show hidden files, folders, and drives [check]
"showsuperhidden"=dword:00000001

;hide folder merge conflicts [uncheck]
"hidemergeconflicts"=dword:00000000

;hide protected operating system files (recommended) [uncheck]
"hidden"=dword:00000001

;use check boxes to select items [check]
"autocheckselect"=dword:00000001

로 저장.*.reg 파일을 클릭하고 액션을 확인하거나 파일에서 (파일) 명령을 실행하여 가져옵니다.

ps: 탐색기 또는 시스템 재시작이 필요하지

레지스트리 키 아래의 레지스트리 항목과 일치합니다.HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AdvancedSet-ItemProperty cmdlet을 사용하여 다음과 같은 값을 변경할 수 있습니다.

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key ShowSuperHidden 1

위의 사용자별 설정과 달리 로컬 컴퓨터에 해당하는 키도 있는 것 같습니다.HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder.

위의 레지스트리 패치는 올바르지만 전체 문제를 해결하지는 못합니다.여기 제가 사용하는 대본이 있습니다.레지스트리의 모든 사용자와 프로파일 디렉토리(기본값을 포함하여 새로 생성된 사용자도 해당 사용자를 포함)를 순환하고 이러한 모든 사용자에 대해 이러한 옵션을 설정합니다.

REM Changes to HKLM are not user-specific

REM Turns "hide file extensions" OFF and "show hidden files" ON.
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\HideFileExt /v DefaultValue /t REG_DWORD /d 0 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL /v DefaultValue /t REG_DWORD /d 1 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v Hidden /t REG_DWORD /d 1 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v ShowSuperHidden /t REG_DWORD /d 1 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v DontPrettyPath /t REG_DWORD /d 1 /f

REM Get path to "Users" dir.
echo WScript.Echo CreateObject("WScript.Shell").RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\ProfilesDirectory") >%temp%\profpath.vbs
for /f "tokens=*" %%i in ('cscript //nologo %temp%\profpath.vbs') do set ProfPath=%%i
del /q %temp%\profpath.vbs


REM Modifies registry keys in for all logged in users
REM Also modify it in the .DEFAULT hive so future users get it.
REM Also edits the registry hive for users who are not logged in
REM This section Copyright Jared Barneck
REM Modified by Ken Carlilep0 and Sam Hills

FOR /F "tokens=2* delims=\" %%a IN ('REG QUERY HKU ^|Findstr /R "DEFAULT S-1-5-[0-9]*-[0-9-]*$"') DO CALL :modkey %%a
For /d %%b in ("%ProfPath%\*") do call :modlokey "%%b"
@REM Exiting here ends the whole batch file.
EXIT /B 0


REM Modify logged-out users
:modlokey
  set RegFile=%~1\ntuser.dat
  REG LOAD HKU\TempHive "%RegFile%">NUL 2>&1
  call :modkey TempHive
  REG UNLOAD HKU\TempHive >NUL 2>&1
EXIT /B 0

REM Modifications to HKEY_USERS go here:
:modkey
REM Turns "hide file extensions" OFF and "show hidden files" ON.
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "HideFileExt" /t REG_DWORD /d "0" /f
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "Hidden" /t REG_DWORD /d "1" /f
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "ShowSuperHidden" /t REG_DWORD /d "1" /f
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "DontPrettyPath" /t REG_DWORD /d "1" /f

REM Combine taskbar buttons only when taskbar is full
REM 0 = Always combine, hide labels, 1 = Combine when taskbar is full, 2 = Never combine
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "TaskbarGlomLevel" /t REG_DWORD /d "1" /f
REM Enable this line if you use multiple monitors:
REM  REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "MMTaskbarGlomLevel" /t REG_DWORD /d "1" /f

REM Don't add "- Shortcut" to new shortcuts
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer" /v "link" /t REG_BINARY /d 00000000 /f

REM Turns on "Computer" Desktop Icon
REG ADD HKU\%1\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel /v "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" /t REG_DWORD /d 0 /f
REG ADD HKU\%1\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu /v "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" /t REG_DWORD /d 0 /f

@REM Exiting here only ends this instance of the call to the
@REM :modkey label. It does not end the whole batch file.
EXIT /B 0

Windows 10(v1703-1809)에서 Powershell을 사용하여 이를 좀 더 자세히 업데이트하면서 다음 코드로 현재 사용자와 로컬 컴퓨터 모두에 대한 폴더 옵션 레지스트리 키를 참조하고 설정할 수 있었습니다.

이전 게시물에서 명확하게 알 수 없었던 가장 큰 깨달음은 폴더 옵션 관련 설정에 대한 reg 키 경로가 키 경로 일관성과 키 값 액세스 모두에서 로컬 컴퓨터 또는 현재 사용자 어느 쪽을 가져오거나 설정할지에 따라 미묘하게 다르다는 것입니다.또한 명확하지 않은 경우 현재 사용자 설정이 로컬 컴퓨터를 재정의합니다.

다음은 PS 5.1에서 테스트한 코드 조각의 예입니다.

## Grab Current User setting(s):
$CUfvHidden      = (Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name 'Hidden').Hidden
$CUfvHideFileExt = (Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name 'HideFileExt').HideFileExt
$CUfvFullPath    = (Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState -Name 'FullPath').FullPath
if ($CUfvHidden -eq 1) { Write-host "CU: Show Hidden set to 'ON'" } #expecting val 1 or 2
else { Write-host "CU: Show Hidden set to 'OFF'" }
if (-not $CUfvHideFileExt) { Write-host "CU: File extensions DISPLAYED" } #expecting val 1 or 0
else { Write-host "CU: File extensions hidden" }
if ($CUfvFullPath) { Write-host "CU: SHOW full path in title bar" } #expecting val 1 or 0
else { Write-host "CU: DO NOT show full path in title bar" }

## Grab Local Machine setting(s)...As you can see the LM reference paths are
## slightly different, to get 1 and 0 values, compared to CU and each other:
$LMfvHidden      = (Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\ShowAll).CheckedValue
$LMfvHideFileExt = (Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\HideFileExt).CheckedValue
$LMfvFullPath    = (Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\ShowFullPath).CheckedValue
if ($LMfvHidden) { Write-host "LM: Show Hidden set to 'ON'" } #expecting val 1 or 2
else { Write-host "LM: Show Hidden set to 'OFF'" }
if (-not $LMfvHideFileExt) { Write-host "LM: File extensions DISPLAYED" } #expecting val 1 or 0
else { Write-host "LM: File extensions hidden" }
if ($LMfvFullPath) { Write-host "LM: SHOW full path in title bar" } #expecting val 1 or 0
else { Write-host "LM: DO NOT show full path in title bar" }

언급URL : https://stackoverflow.com/questions/4491999/configure-windows-explorer-folder-options-through-powershell

반응형