Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $error.clear()
- cls
- 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
- }
- foreach ($guid in $KnownFolders[$KnownFolder])
- {
- [WinAPI.KnownFolders]::SHSetKnownFolderPath([ref]$guid, 0, 0, $Path)
- }
- (Get-Item -Path $Path -Force).Attributes = "ReadOnly"
- }
- function UserShellFolder
- {
- param
- (
- [Parameter(Mandatory = $true)]
- [ValidateSet("Desktop", "Documents", "Downloads", "Music", "Pictures", "Videos")]
- [string]
- $UserFolder,
- [Parameter(Mandatory = $true)]
- [string]
- $Path
- )
- $UserShellFoldersRegName = @{
- "Desktop" = "Desktop"
- "Documents" = "Personal"
- "Downloads" = "{374DE290-123F-4565-9164-39C4925E467B}"
- "Music" = "My Music"
- "Pictures" = "My Pictures"
- "Videos" = "My Video"
- }
- $UserShellFoldersGUID = @{
- "Desktop" = "{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}"
- "Documents" = "{F42EE2D3-909F-4907-8871-4C22FC0BF756}"
- "Downloads" = "{7D83EE9B-2244-4E70-B1F5-5393042AF1E4}"
- "Music" = "{A0C69A99-21C8-4671-8703-7934162FCF1D}"
- "Pictures" = "{0DDD015D-B06C-45D5-8C4C-F59713854639}"
- "Videos" = "{35286A68-3C57-41A1-BBB1-0EAE73D76C95}"
- }
- $DesktopINI = @{
- "Desktop" = "",
- "[.ShellClassInfo]",
- "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21769",
- "IconResource=%SystemRoot%\system32\imageres.dll,-183"
- "Documents" = "",
- "[.ShellClassInfo]",
- "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21770",
- "IconResource=%SystemRoot%\system32\imageres.dll,-112",
- "IconFile=%SystemRoot%\system32\shell32.dll",
- "IconIndex=-235"
- "Downloads" = "",
- "[.ShellClassInfo]","LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21798",
- "IconResource=%SystemRoot%\system32\imageres.dll,-184"
- "Music" = "",
- "[.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" = "",
- "[.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" = "",
- "[.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"
- }
- $FolderPath = "$Path\$UserFolder"
- $UserShellFolderRegValue = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersRegName[$UserFolder]
- if ($UserShellFolderRegValue -ne $FolderPath)
- {
- if ((Get-ChildItem -Path $UserShellFolderRegValue | Measure-Object).Count -ne 0)
- {
- if ($RU)
- {
- Write-Error -Message "В папке $UserShellFolderRegValue осталась информация" -ErrorAction SilentlyContinue
- }
- else
- {
- Write-Error -Message "The $UserShellFolderRegValue folder is not empty" -ErrorAction SilentlyContinue
- }
- }
- if (-not (Test-Path -Path $FolderPath))
- {
- New-Item -Path $FolderPath -ItemType Directory -Force
- }
- KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath
- New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUID[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force
- Set-Content -Path "$FolderPath\desktop.ini" -Value $DesktopINI[$UserFolder] -Encoding Unicode -Force
- (Get-Item -Path "$FolderPath\desktop.ini" -Force).Attributes = "Hidden", "System", "Archive"
- (Get-Item -Path "$FolderPath\desktop.ini" -Force).Refresh()
- }
- }
- function Menu
- {
- param
- (
- [Parameter(Mandatory = $true)]
- [string]
- $Title,
- [Parameter(Mandatory = $true)]
- [array]
- $Options
- )
- $MaxValue = $Options.Count - 1
- $Selection = 0
- $EnterPressed = $false
- Clear-Host
- while ($EnterPressed -eq $false)
- {
- Write-Host $Title
- for ($i = 0; $i -le $MaxValue; $i++)
- {
- if ($i -eq $Selection)
- {
- Write-Host "[ $($Options[$i]) ]" -BackgroundColor Cyan -ForegroundColor Black
- }
- else
- {
- Write-Host " $($Options[$i]) "
- }
- }
- $KeyInput = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").VirtualKeyCode
- switch ($KeyInput)
- {
- "13"
- {
- # enter key
- $EnterPressed = $true
- return $Selection
- Clear-Host
- break
- }
- "38"
- {
- # down key
- if ($Selection -eq 0)
- {
- $Selection = $MaxValue
- }
- else
- {
- $Selection -= 1
- }
- Clear-Host
- break
- }
- "40"
- {
- # up key
- if ($Selection -eq $MaxValue)
- {
- $Selection = 0
- }
- else
- {
- $Selection +=1
- }
- Clear-Host
- break
- }
- Default
- {
- Clear-Host
- }
- }
- }
- }
- $Options = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object)
- if ($RU)
- {
- $Title = "Выберите букву диска"
- }
- else
- {
- $Title = "Desktop"
- }
- Menu -Title $Title -Options $Options
- $Selected = $Options[(Menu -Title $Title -Options $Options)]
- $Selected = "${selected}:"
- UserShellFolder -UserFolder Desktop -Path $selected
- if ($RU)
- {
- $Title = "Выберите букву диска"
- }
- else
- {
- $Title = "Documents"
- }
- Menu -Title $Title -Options $Options
- $Selected = $Options[(Menu -Title $Title -Options $Options)]
- $Selected = "${selected}:"
- UserShellFolder -UserFolder Documents -Path $selected
- if ($RU)
- {
- $Title = "Выберите букву диска"
- }
- else
- {
- $Title = "Downloads"
- }
- Menu -Title $Title -Options $Options
- $Selected = $Options[(Menu -Title $Title -Options $Options)]
- $Selected = "${selected}:"
- UserShellFolder -UserFolder Downloads -Path $selected
- if ($RU)
- {
- $Title = "Выберите букву диска"
- }
- else
- {
- $Title = "Music"
- }
- Menu -Title $Title -Options $Options
- $Selected = $Options[(Menu -Title $Title -Options $Options)]
- $Selected = "${selected}:"
- UserShellFolder -UserFolder Music -Path $selected
- if ($RU)
- {
- $Title = "Выберите букву диска"
- }
- else
- {
- $Title = "Pictures"
- }
- Menu -Title $Title -Options $Options
- $Selected = $Options[(Menu -Title $Title -Options $Options)]
- $Selected = "${selected}:"
- UserShellFolder -UserFolder Pictures -Path $selected
- if ($RU)
- {
- $Title = "Выберите букву диска"
- }
- else
- {
- $Title = "Videos"
- }
- Menu -Title $Title -Options $Options
- $Selected = $Options[(Menu -Title $Title -Options $Options)]
- $Selected = "${selected}:"
- UserShellFolder -UserFolder Videos -Path $selected
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement