Function KnownFolderPath {
Param ( [Parameter(Mandatory = $true)]
[ValidateSet("Desktop", "Documents", "Downloads", "Music", "Pictures", "Videos")]
[string]$KnownFolder,
[Parameter(Mandatory = $true)]
[string]$Path )
$KnownFolders = @{"Desktop" = @("B4BFCC3A-DB2C-424C-B029-7FE99A87C641")
"Documents" = @("FDD39AD0-238F-46AF-ADB4-6C85480369C7", "f42ee2d3-909f-4907-8871-4c22fc0bf756")
"Downloads" = @("374DE290-123F-4565-9164-39C4925E467B", "7d83ee9b-2244-4e70-b1f5-5393042af1e4")
"Music" = @("4BD8D571-6D19-48D3-BE97-422220080E43", "a0c69a99-21c8-4671-8703-7934162fcf1d")
"Pictures" = @("33E28130-4E1E-4676-835A-98395C3BC3BB", "0ddd015d-b06c-45d5-8c4c-f59713854639")
"Videos" = @("18989B1D-99B5-455B-841C-AB7C74E4DDFC", "35286a68-3c57-41a1-bbb1-0eae73d76c95")}
$Signature = @{Namespace = "WinAPI"
Name = "KnownFolders"
Language = "CSharp"
MemberDefinition = @"
[DllImport("shell32.dll")]
public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, IntPtr token, [MarshalAs(UnmanagedType.LPWStr)] string path);
"@}
if (-not ("WinAPI.KnownFolders" -as [type])) {Add-Type @Signature}
$KnownFolders[$KnownFolder] | %{[WinAPI.KnownFolders]::SHSetKnownFolderPath([ref]$_, 0, 0, $Path)}
(Get-Item -Path $Path -Force ).Attributes = "ReadOnly"
}
function Set-UserLibrary {
param (
[Parameter(Mandatory = $true)]
[string]$Path,
[Parameter(Mandatory = $true)]
[string]$LibraryName
)
$LibraryFolder = "$($Path -Replace('/+', '\') -Replace('\\\\+', '\') -Replace('\\*$', ''))\$LibraryName"
if ($Script:Drives.Contains($LibraryFolder.Substring(0,3).ToUpper())) {
$Reg = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $LibraryINI.$LibraryName[0][0]
if ($Reg -ne $LibraryFolder) {
if (-not (Test-Path -Path $LibraryFolder)) {New-Item -Path $LibraryFolder -ItemType Directory -Force}
KnownFolderPath -KnownFolder $LibraryName -Path $LibraryFolder
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $LibraryINI.$LibraryName[0][1] -PropertyType ExpandString -Value $LibraryFolder -Force
Set-Content -Path "$LibraryFolder\desktop.ini" -Value $LibraryINI.$LibraryName[1] -Encoding Unicode -Force
(Get-Item -Path "$LibraryFolder\desktop.ini" -Force).Attributes = "Hidden", "System", "Archive"
(Get-Item -Path "$LibraryFolder\desktop.ini" -Force).Refresh()
}
}
}
[hashtable] $LibraryINI = @{
"Desktop" = @("Desktop", "{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}"),
@("", "[.ShellClassInfo]", "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21769",
"IconResource=%SystemRoot%\system32\imageres.dll,-183")
"Documents" = @("Personal", "{F42EE2D3-909F-4907-8871-4C22FC0BF756}"),
@("", "[.ShellClassInfo]", "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21770",
"IconResource=%SystemRoot%\system32\imageres.dll,-112",
"IconFile=%SystemRoot%\system32\shell32.dll", "IconIndex=-235")
"Downloads" = @("{374DE290-123F-4565-9164-39C4925E467B}", "{7D83EE9B-2244-4E70-B1F5-5393042AF1E4}"),
@("", "[.ShellClassInfo]","LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21798",
"IconResource=%SystemRoot%\system32\imageres.dll,-184")
"Music" = @("My Music", "{A0C69A99-21C8-4671-8703-7934162FCF1D}"),
@("", "[.ShellClassInfo]","LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21790",
"InfoTip=@%SystemRoot%\system32\shell32.dll,-12689",
"IconResource=%SystemRoot%\system32\imageres.dll,-108",
"IconFile=%SystemRoot%\system32\shell32.dll", "IconIndex=-237")
"Pictures" = @("My Pictures", "{0DDD015D-B06C-45D5-8C4C-F59713854639}"),
@("", "[.ShellClassInfo]", "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21779",
"InfoTip=@%SystemRoot%\system32\shell32.dll,-12688",
"IconResource=%SystemRoot%\system32\imageres.dll,-113",
"IconFile=%SystemRoot%\system32\shell32.dll", "IconIndex=-236")
"Videos" = @("My Video", "{35286A68-3C57-41A1-BBB1-0EAE73D76C95}"),
@("", "[.ShellClassInfo]", "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21791",
"InfoTip=@%SystemRoot%\system32\shell32.dll,-12690",
"IconResource=%SystemRoot%\system32\imageres.dll,-189",
"IconFile=%SystemRoot%\system32\shell32.dll", "IconIndex=-238")
}
$Drives = (Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume).DriveLetter | Sort-Object -Unique | ?{$_.Length -gt 0 } | %{"$($_):\"}
Write-Host "Ваши диски: " -NoNewline
Write-Host "$($Drives -join ', ')" -ForegroundColor Yellow
Write-Host "`nВведите путь, по которому будут перенесены такие библиотеки пользователя, как:" -NoNewline
Write-Host "`n`"Рабочий стол`", `"Документы`", `"Загрузки`", `"Музыка`", `"Изображения`", `"Видео`"." -ForegroundColor Yellow
Write-Host "`nЧтобы пропустить, нажмите Enter."
$LibraryPath = Read-Host -Prompt "Введите путь"
if ($LibraryPath) {
$LibraryINI.Keys | %{Set-UserLibrary -Path $LibraryPath -LibraryName $_}
$edge = (Get-AppxPackage "Microsoft.MicrosoftEdge").PackageFamilyName
New-ItemProperty -Path "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\$edge\MicrosoftEdge\Main" -Name "Default Download Directory" -PropertyType String -Value "$LibraryPath\Downloads" -Force
}