Advertisement
Guest User

Untitled

a guest
May 19th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $error.clear()
  2. cls
  3. function KnownFolderPath
  4. {
  5.     param
  6.     (
  7.         [Parameter(Mandatory = $true)]
  8.         [ValidateSet("Desktop", "Documents", "Downloads", "Music", "Pictures", "Videos")]
  9.         [string]
  10.         $KnownFolder,
  11.  
  12.         [Parameter(Mandatory = $true)]
  13.         [string]
  14.         $Path
  15.     )
  16.     $KnownFolders = @{
  17.         "Desktop"   = @("B4BFCC3A-DB2C-424C-B029-7FE99A87C641");
  18.         "Documents" = @("FDD39AD0-238F-46AF-ADB4-6C85480369C7", "f42ee2d3-909f-4907-8871-4c22fc0bf756");
  19.         "Downloads" = @("374DE290-123F-4565-9164-39C4925E467B", "7d83ee9b-2244-4e70-b1f5-5393042af1e4");
  20.         "Music"     = @("4BD8D571-6D19-48D3-BE97-422220080E43", "a0c69a99-21c8-4671-8703-7934162fcf1d");
  21.         "Pictures"  = @("33E28130-4E1E-4676-835A-98395C3BC3BB", "0ddd015d-b06c-45d5-8c4c-f59713854639");
  22.         "Videos"    = @("18989B1D-99B5-455B-841C-AB7C74E4DDFC", "35286a68-3c57-41a1-bbb1-0eae73d76c95");
  23.     }
  24.     $Signature = @{
  25.         Namespace = "WinAPI"
  26.         Name = "KnownFolders"
  27.         Language = "CSharp"
  28.         MemberDefinition = @"
  29.             [DllImport("shell32.dll")]
  30.             public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, IntPtr token, [MarshalAs(UnmanagedType.LPWStr)] string path);
  31. "@
  32.     }
  33.     if (-not ("WinAPI.KnownFolders" -as [type]))
  34.     {
  35.         Add-Type @Signature
  36.     }
  37.     foreach ($guid in $KnownFolders[$KnownFolder])
  38.     {
  39.         [WinAPI.KnownFolders]::SHSetKnownFolderPath([ref]$guid, 0, 0, $Path)
  40.     }
  41.     (Get-Item -Path $Path -Force).Attributes = "ReadOnly"
  42. }
  43.  
  44. function UserShellFolder
  45. {
  46.     param
  47.     (
  48.         [Parameter(Mandatory = $true)]
  49.         [ValidateSet("Desktop", "Documents", "Downloads", "Music", "Pictures", "Videos")]
  50.         [string]
  51.         $UserFolder,
  52.  
  53.         [Parameter(Mandatory = $true)]
  54.         [string]
  55.         $Path
  56.     )
  57.  
  58.     $UserShellFoldersRegName = @{
  59.         "Desktop"   =   "Desktop"
  60.         "Documents" =   "Personal"
  61.         "Downloads" =   "{374DE290-123F-4565-9164-39C4925E467B}"
  62.         "Music"     =   "My Music"
  63.         "Pictures"  =   "My Pictures"
  64.         "Videos"    =   "My Video"
  65.     }
  66.  
  67.     $UserShellFoldersGUID = @{
  68.         "Desktop"   =   "{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}"
  69.         "Documents" =   "{F42EE2D3-909F-4907-8871-4C22FC0BF756}"
  70.         "Downloads" =   "{7D83EE9B-2244-4E70-B1F5-5393042AF1E4}"
  71.         "Music"     =   "{A0C69A99-21C8-4671-8703-7934162FCF1D}"
  72.         "Pictures"  =   "{0DDD015D-B06C-45D5-8C4C-F59713854639}"
  73.         "Videos"    =   "{35286A68-3C57-41A1-BBB1-0EAE73D76C95}"
  74.     }
  75.  
  76.     $DesktopINI = @{
  77.         "Desktop"   =   "",
  78.                         "[.ShellClassInfo]",
  79.                         "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21769",
  80.                         "IconResource=%SystemRoot%\system32\imageres.dll,-183"
  81.         "Documents" =   "",
  82.                         "[.ShellClassInfo]",
  83.                         "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21770",
  84.                         "IconResource=%SystemRoot%\system32\imageres.dll,-112",
  85.                         "IconFile=%SystemRoot%\system32\shell32.dll",
  86.                         "IconIndex=-235"
  87.         "Downloads" =   "",
  88.                         "[.ShellClassInfo]","LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21798",
  89.                         "IconResource=%SystemRoot%\system32\imageres.dll,-184"
  90.         "Music"     =   "",
  91.                         "[.ShellClassInfo]","LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21790",
  92.                         "InfoTip=@%SystemRoot%\system32\shell32.dll,-12689",
  93.                         "IconResource=%SystemRoot%\system32\imageres.dll,-108",
  94.                         "IconFile=%SystemRoot%\system32\shell32.dll","IconIndex=-237"
  95.         "Pictures"  =   "",
  96.                         "[.ShellClassInfo]",
  97.                         "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21779",
  98.                         "InfoTip=@%SystemRoot%\system32\shell32.dll,-12688",
  99.                         "IconResource=%SystemRoot%\system32\imageres.dll,-113",
  100.                         "IconFile=%SystemRoot%\system32\shell32.dll",
  101.                         "IconIndex=-236"
  102.         "Videos"    =   "",
  103.                         "[.ShellClassInfo]",
  104.                         "LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21791",
  105.                         "InfoTip=@%SystemRoot%\system32\shell32.dll,-12690",
  106.                         "IconResource=%SystemRoot%\system32\imageres.dll,-189",
  107.                         "IconFile=%SystemRoot%\system32\shell32.dll","IconIndex=-238"
  108.     }
  109.  
  110.     $FolderPath = "$Path\$UserFolder"
  111.     $UserShellFolderRegValue = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersRegName[$UserFolder]
  112.     if ($UserShellFolderRegValue -ne $FolderPath)
  113.     {
  114.         if ((Get-ChildItem -Path $UserShellFolderRegValue | Measure-Object).Count -ne 0)
  115.         {
  116.             if ($RU)
  117.             {
  118.                 Write-Error -Message "В папке $UserShellFolderRegValue осталась информация" -ErrorAction SilentlyContinue
  119.             }
  120.             else
  121.             {
  122.                 Write-Error -Message "The $UserShellFolderRegValue folder is not empty" -ErrorAction SilentlyContinue
  123.             }
  124.         }
  125.         if (-not (Test-Path -Path $FolderPath))
  126.         {
  127.             New-Item -Path $FolderPath -ItemType Directory -Force
  128.         }
  129.         KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath
  130.         New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUID[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force
  131.         Set-Content -Path "$FolderPath\desktop.ini" -Value $DesktopINI[$UserFolder] -Encoding Unicode -Force
  132.         (Get-Item -Path "$FolderPath\desktop.ini" -Force).Attributes = "Hidden", "System", "Archive"
  133.         (Get-Item -Path "$FolderPath\desktop.ini" -Force).Refresh()
  134.     }
  135. }
  136.  
  137. function Menu
  138. {
  139.     param
  140.     (
  141.         [Parameter(Mandatory = $true)]
  142.         [string]
  143.         $Title,
  144.  
  145.         [Parameter(Mandatory = $true)]
  146.         [array]
  147.         $Options
  148.     )
  149.  
  150.     $MaxValue = $Options.Count - 1
  151.     $Selection = 0
  152.     $EnterPressed = $false
  153.  
  154.     Clear-Host
  155.  
  156.     while ($EnterPressed -eq $false)
  157.     {
  158.         Write-Host $Title
  159.  
  160.         for ($i = 0; $i -le $MaxValue; $i++)
  161.         {
  162.             if ($i -eq $Selection)
  163.             {
  164.                 Write-Host "[ $($Options[$i]) ]" -BackgroundColor Cyan -ForegroundColor Black
  165.             }
  166.             else
  167.             {
  168.                 Write-Host "  $($Options[$i])  "
  169.             }
  170.         }
  171.  
  172.         $KeyInput = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").VirtualKeyCode
  173.  
  174.         switch ($KeyInput)
  175.         {
  176.             "13"
  177.             {
  178.                 # enter key
  179.                 $EnterPressed = $true
  180.                 return $Selection
  181.                 Clear-Host
  182.                 break
  183.             }
  184.  
  185.             "38"
  186.             {
  187.                 # down key
  188.                 if ($Selection -eq 0)
  189.                 {
  190.                     $Selection = $MaxValue
  191.                 }
  192.                 else
  193.                 {
  194.                     $Selection -= 1
  195.                 }
  196.                 Clear-Host
  197.                 break
  198.             }
  199.  
  200.             "40"
  201.             {
  202.                 # up key
  203.                 if ($Selection -eq $MaxValue)
  204.                 {
  205.                     $Selection = 0
  206.                 }
  207.                 else
  208.                 {
  209.                     $Selection +=1
  210.                 }
  211.                 Clear-Host
  212.                 break
  213.             }
  214.             Default
  215.             {
  216.                 Clear-Host
  217.             }
  218.         }
  219.     }
  220. }
  221.  
  222. $Options = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object)
  223.  
  224. if ($RU)
  225. {
  226.     $Title = "Выберите букву диска"
  227. }
  228. else
  229. {
  230.     $Title = "Desktop"
  231. }
  232. Menu -Title $Title -Options $Options
  233. $Selected = $Options[(Menu -Title $Title -Options $Options)]
  234. $Selected = "${selected}:"
  235. UserShellFolder -UserFolder Desktop -Path $selected
  236.  
  237. if ($RU)
  238. {
  239.     $Title = "Выберите букву диска"
  240. }
  241. else
  242. {
  243.     $Title = "Documents"
  244. }
  245. Menu -Title $Title -Options $Options
  246. $Selected = $Options[(Menu -Title $Title -Options $Options)]
  247. $Selected = "${selected}:"
  248. UserShellFolder -UserFolder Documents -Path $selected
  249.  
  250. if ($RU)
  251. {
  252.     $Title = "Выберите букву диска"
  253. }
  254. else
  255. {
  256.     $Title = "Downloads"
  257. }
  258. Menu -Title $Title -Options $Options
  259. $Selected = $Options[(Menu -Title $Title -Options $Options)]
  260. $Selected = "${selected}:"
  261. UserShellFolder -UserFolder Downloads -Path $selected
  262.  
  263. if ($RU)
  264. {
  265.     $Title = "Выберите букву диска"
  266. }
  267. else
  268. {
  269.     $Title = "Music"
  270. }
  271. Menu -Title $Title -Options $Options
  272. $Selected = $Options[(Menu -Title $Title -Options $Options)]
  273. $Selected = "${selected}:"
  274. UserShellFolder -UserFolder Music -Path $selected
  275.  
  276. if ($RU)
  277. {
  278.     $Title = "Выберите букву диска"
  279. }
  280. else
  281. {
  282.     $Title = "Pictures"
  283. }
  284. Menu -Title $Title -Options $Options
  285. $Selected = $Options[(Menu -Title $Title -Options $Options)]
  286. $Selected = "${selected}:"
  287. UserShellFolder -UserFolder Pictures -Path $selected
  288.  
  289. if ($RU)
  290. {
  291.     $Title = "Выберите букву диска"
  292. }
  293. else
  294. {
  295.     $Title = "Videos"
  296. }
  297. Menu -Title $Title -Options $Options
  298. $Selected = $Options[(Menu -Title $Title -Options $Options)]
  299. $Selected = "${selected}:"
  300. UserShellFolder -UserFolder Videos -Path $selected
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement