diff --git a/Wrapper/Config/config_Windows_10.json b/Wrapper/Config/config_Windows_10.json index ff21b2d9..554f4872 100644 --- a/Wrapper/Config/config_Windows_10.json +++ b/Wrapper/Config/config_Windows_10.json @@ -1371,7 +1371,7 @@ "Region": "System", "Control": "cmb", "Required": "false", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root" diff --git a/Wrapper/Config/config_Windows_10_LTSC.json b/Wrapper/Config/config_Windows_10_LTSC.json index 0cca839b..c2b3b83f 100644 --- a/Wrapper/Config/config_Windows_10_LTSC.json +++ b/Wrapper/Config/config_Windows_10_LTSC.json @@ -1507,7 +1507,7 @@ "Region": "System", "Control": "cmb", "Required": "false", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root" diff --git a/Wrapper/Config/config_Windows_11.json b/Wrapper/Config/config_Windows_11.json index b2fe779a..2fc910af 100644 --- a/Wrapper/Config/config_Windows_11.json +++ b/Wrapper/Config/config_Windows_11.json @@ -1251,7 +1251,7 @@ "Region": "System", "Control": "cmb", "Required": "false", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root" diff --git a/Wrapper/Localizations/de-DE/tooltip_Windows_10.json b/Wrapper/Localizations/de-DE/tooltip_Windows_10.json index 97825cea..dec7fd64 100644 --- a/Wrapper/Localizations/de-DE/tooltip_Windows_10.json +++ b/Wrapper/Localizations/de-DE/tooltip_Windows_10.json @@ -1226,7 +1226,7 @@ { "Id": 520, "Region": "System", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root", diff --git a/Wrapper/Localizations/de-DE/tooltip_Windows_11.json b/Wrapper/Localizations/de-DE/tooltip_Windows_11.json index 673aca31..4cb6dd92 100644 --- a/Wrapper/Localizations/de-DE/tooltip_Windows_11.json +++ b/Wrapper/Localizations/de-DE/tooltip_Windows_11.json @@ -1121,7 +1121,7 @@ { "Id": 520, "Region": "System", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root", diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_10.json b/Wrapper/Localizations/en-US/tooltip_Windows_10.json index dfb74815..47bfb5cf 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_10.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_10.json @@ -1226,11 +1226,11 @@ { "Id": 520, "Region": "System", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root", - "ToolTip": "Move user folders location to the root of any drive using the interactive menu. User files or folders won't me moved to a new location. Move them manually. They're located in the %USERPROFILE% folder by default" + "ToolTip": "Change user folders location to the root of any drive using the interactive menu. User files or folders won't me moved to a new location. Move them manually. They're located in the %USERPROFILE% folder by default" }, "One": { "Tag": "Custom", diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_11.json b/Wrapper/Localizations/en-US/tooltip_Windows_11.json index c2fb3005..7e0ae63a 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_11.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_11.json @@ -1121,11 +1121,11 @@ { "Id": 520, "Region": "System", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root", - "ToolTip": "Move user folders location to the root of any drive using the interactive menu. User files or folders won't me moved to a new location. Move them manually. They're located in the %USERPROFILE% folder by default" + "ToolTip": "Change user folders location to the root of any drive using the interactive menu. User files or folders won't me moved to a new location. Move them manually. They're located in the %USERPROFILE% folder by default" }, "One": { "Tag": "Custom", diff --git a/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json b/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json index a3596762..e3a98a28 100644 --- a/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json +++ b/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json @@ -1226,7 +1226,7 @@ { "Id": 520, "Region": "System", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root", diff --git a/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json b/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json index 23cfb92f..91c6d265 100644 --- a/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json +++ b/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json @@ -1136,7 +1136,7 @@ { "Id": 520, "Region": "System", - "Function": "SetUserShellFolderLocation", + "Function": "Set-UserShellFolderLocation", "Arg": { "Zero": { "Tag": "Root", diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 368ad792..a6f9110a 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -6658,10 +6658,10 @@ function InputMethod <# .SYNOPSIS - User folders location + Change User folders location .PARAMETER Root - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu .PARAMETER Custom Select folders for user folders location manually using a folder browser dialog @@ -6670,13 +6670,13 @@ function InputMethod Change user folders location to the default values .EXAMPLE - SetUserShellFolderLocation -Root + Set-UserShellFolderLocation -Root .EXAMPLE - SetUserShellFolderLocation -Custom + Set-UserShellFolderLocation -Custom .EXAMPLE - SetUserShellFolderLocation -Default + Set-UserShellFolderLocation -Default .NOTES User files or folders won't me moved to a new location @@ -6684,7 +6684,7 @@ function InputMethod .NOTES Current user #> -function SetUserShellFolderLocation +function Set-UserShellFolderLocation { param @@ -6719,7 +6719,7 @@ function SetUserShellFolderLocation The RemoveDesktopINI argument removes desktop.ini in the old user shell folder .EXAMPLE - UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI .LINK https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath @@ -6727,7 +6727,7 @@ function SetUserShellFolderLocation .NOTES User files or folders won't me moved to a new location #> - function UserShellFolder + function Set-UserShellFolder { [CmdletBinding()] param @@ -6751,9 +6751,9 @@ function SetUserShellFolderLocation Redirect user folders to a new location .EXAMPLE - KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" + Set-KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" #> - function KnownFolderPath + function Set-KnownFolderPath { [CmdletBinding()] param @@ -6872,7 +6872,7 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int Remove-Item -Path "$CurrentUserFolderPath\desktop.ini" -Force -ErrorAction Ignore } - KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath + Set-KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUIDs[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force # Save desktop.ini in the UTF-16 LE encoding @@ -6999,26 +6999,22 @@ public static string GetString(uint strId) Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.RetrievingDrivesList -Verbose - # Store all drives letters to use them within ShowMenu function - $DriveLetters = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object) + # Store all fixed disks' letters to use them within ShowMenu function + # https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype?view=net-7.0#fields + $DriveLetters = @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object) # If the number of disks is more than one, set the second drive in the list as default drive if ($DriveLetters.Count -gt 1) { $Script:Default = 1 } - else - { - $Script:Default = 0 - } # Desktop + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DesktopLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7033,23 +7029,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}:\Desktop" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DocumentsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7064,23 +7065,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DocumentsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}:\Documents" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DownloadsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7095,23 +7101,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DownloadsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}:\Downloads" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}\Downloads" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $MusicLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7126,23 +7137,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $MusicLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}:\Music" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $PicturesLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7157,23 +7173,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $PicturesLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}:\Pictures" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $VideosLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7188,12 +7209,18 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $VideosLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}:\Videos" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -7201,10 +7228,10 @@ public static string GetString(uint strId) "Custom" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7230,22 +7257,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7271,22 +7297,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7312,22 +7337,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7353,22 +7377,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7394,22 +7417,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7435,13 +7457,12 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -7449,10 +7470,10 @@ public static string GetString(uint strId) "Default" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7467,20 +7488,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7495,20 +7515,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7523,20 +7542,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI } "1" { Write-Verbose -Message $Localization.Skipped -Verbose - Write-Information -MessageData "" -InformationAction Continue } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7551,20 +7569,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7579,24 +7596,21 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved - Write-Information -MessageData "" -InformationAction Continue - $Title = "" $Message = $Localization.UserDefaultFolder -f $VideosLocalizedString $Yes = $Localization.Yes @@ -7609,11 +7623,10 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } diff --git a/src/Sophia_Script_for_Windows_10/Sophia.ps1 b/src/Sophia_Script_for_Windows_10/Sophia.ps1 index b6839668..a49665cb 100644 --- a/src/Sophia_Script_for_Windows_10/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10/Sophia.ps1 @@ -779,7 +779,7 @@ InputMethod -English # InputMethod -Default <# - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu User files or folders won't me moved to a new location. Move them manually They're located in the %USERPROFILE% folder by default @@ -787,7 +787,7 @@ InputMethod -English Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -SetUserShellFolderLocation -Root +Set-UserShellFolderLocation -Root <# Select folders for user folders location manually using a folder browser dialog @@ -798,7 +798,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Custom +# Set-UserShellFolderLocation -Custom <# Change user folders location to the default values @@ -809,7 +809,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Default +# Set-UserShellFolderLocation -Default # Use the latest installed .NET runtime for all apps # Использовать последнюю установленную среду выполнения .NET для всех приложений diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 index 37d1c21a..3ae7af62 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 @@ -5317,10 +5317,10 @@ function InputMethod <# .SYNOPSIS - User folders location + Change User folders location .PARAMETER Root - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu .PARAMETER Custom Select folders for user folders location manually using a folder browser dialog @@ -5329,13 +5329,13 @@ function InputMethod Change user folders location to the default values .EXAMPLE - SetUserShellFolderLocation -Root + Set-UserShellFolderLocation -Root .EXAMPLE - SetUserShellFolderLocation -Custom + Set-UserShellFolderLocation -Custom .EXAMPLE - SetUserShellFolderLocation -Default + Set-UserShellFolderLocation -Default .NOTES User files or folders won't me moved to a new location @@ -5343,7 +5343,7 @@ function InputMethod .NOTES Current user #> -function SetUserShellFolderLocation +function Set-UserShellFolderLocation { param @@ -5378,7 +5378,7 @@ function SetUserShellFolderLocation The RemoveDesktopINI argument removes desktop.ini in the old user shell folder .EXAMPLE - UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI .LINK https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath @@ -5386,7 +5386,7 @@ function SetUserShellFolderLocation .NOTES User files or folders won't me moved to a new location #> - function UserShellFolder + function Set-UserShellFolder { [CmdletBinding()] param @@ -5410,9 +5410,9 @@ function SetUserShellFolderLocation Redirect user folders to a new location .EXAMPLE - KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" + Set-KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" #> - function KnownFolderPath + function Set-KnownFolderPath { [CmdletBinding()] param @@ -5531,7 +5531,7 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int Remove-Item -Path "$CurrentUserFolderPath\desktop.ini" -Force -ErrorAction Ignore } - KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath + Set-KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUIDs[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force # Save desktop.ini in the UTF-16 LE encoding @@ -5658,26 +5658,22 @@ public static string GetString(uint strId) Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.RetrievingDrivesList -Verbose - # Store all drives letters to use them within ShowMenu function - $DriveLetters = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object) + # Store all fixed disks' letters to use them within ShowMenu function + # https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype?view=net-7.0#fields + $DriveLetters = @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object) # If the number of disks is more than one, set the second drive in the list as default drive if ($DriveLetters.Count -gt 1) { $Script:Default = 1 } - else - { - $Script:Default = 0 - } # Desktop + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DesktopLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5692,23 +5688,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}:\Desktop" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DocumentsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5723,23 +5724,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DocumentsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}:\Documents" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DownloadsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5754,23 +5760,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DownloadsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}:\Downloads" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}\Downloads" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $MusicLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5785,23 +5796,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $MusicLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}:\Music" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $PicturesLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5816,23 +5832,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $PicturesLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}:\Pictures" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $VideosLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5847,12 +5868,18 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $VideosLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}:\Videos" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -5860,10 +5887,10 @@ public static string GetString(uint strId) "Custom" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5889,22 +5916,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5930,22 +5956,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -5971,22 +5996,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6012,22 +6036,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6053,22 +6076,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6094,13 +6116,12 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -6108,10 +6129,10 @@ public static string GetString(uint strId) "Default" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6126,20 +6147,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6154,20 +6174,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6182,20 +6201,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI } "1" { Write-Verbose -Message $Localization.Skipped -Verbose - Write-Information -MessageData "" -InformationAction Continue } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6210,20 +6228,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6238,24 +6255,21 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved - Write-Information -MessageData "" -InformationAction Continue - $Title = "" $Message = $Localization.UserDefaultFolder -f $VideosLocalizedString $Yes = $Localization.Yes @@ -6268,11 +6282,10 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 index fc6b5476..c8da51ec 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 @@ -637,7 +637,7 @@ InputMethod -English # InputMethod -Default <# - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu User files or folders won't me moved to a new location. Move them manually They're located in the %USERPROFILE% folder by default @@ -645,7 +645,7 @@ InputMethod -English Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -SetUserShellFolderLocation -Root +Set-UserShellFolderLocation -Root <# Select folders for user folders location manually using a folder browser dialog @@ -656,7 +656,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Custom +# Set-UserShellFolderLocation -Custom <# Change user folders location to the default values @@ -667,7 +667,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Default +# Set-UserShellFolderLocation -Default # Use the latest installed .NET runtime for all apps # Использовать последнюю установленную среду выполнения .NET для всех приложений diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index d50fa0e9..b5262759 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -5704,10 +5704,10 @@ function InputMethod <# .SYNOPSIS - User folders location + Change User folders location .PARAMETER Root - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu .PARAMETER Custom Select folders for user folders location manually using a folder browser dialog @@ -5716,13 +5716,13 @@ function InputMethod Change user folders location to the default values .EXAMPLE - SetUserShellFolderLocation -Root + Set-UserShellFolderLocation -Root .EXAMPLE - SetUserShellFolderLocation -Custom + Set-UserShellFolderLocation -Custom .EXAMPLE - SetUserShellFolderLocation -Default + Set-UserShellFolderLocation -Default .NOTES User files or folders won't me moved to a new location @@ -5730,7 +5730,7 @@ function InputMethod .NOTES Current user #> -function SetUserShellFolderLocation +function Set-UserShellFolderLocation { param @@ -5765,7 +5765,7 @@ function SetUserShellFolderLocation The RemoveDesktopINI argument removes desktop.ini in the old user shell folder .EXAMPLE - UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI .LINK https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath @@ -5773,7 +5773,7 @@ function SetUserShellFolderLocation .NOTES User files or folders won't me moved to a new location #> - function UserShellFolder + function Set-UserShellFolder { [CmdletBinding()] param @@ -5797,9 +5797,9 @@ function SetUserShellFolderLocation Redirect user folders to a new location .EXAMPLE - KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" + Set-KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" #> - function KnownFolderPath + function Set-KnownFolderPath { [CmdletBinding()] param @@ -5918,7 +5918,7 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int Remove-Item -Path "$CurrentUserFolderPath\desktop.ini" -Force -ErrorAction Ignore } - KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath + Set-KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUIDs[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force # Save desktop.ini in the UTF-16 LE encoding @@ -6045,26 +6045,22 @@ public static string GetString(uint strId) Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.RetrievingDrivesList -Verbose - # Store all drives letters to use them within ShowMenu function - $DriveLetters = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object) + # Store all fixed disks' letters to use them within ShowMenu function + # https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype?view=net-7.0#fields + $DriveLetters = @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object) # If the number of disks is more than one, set the second drive in the list as default drive if ($DriveLetters.Count -gt 1) { $Script:Default = 1 } - else - { - $Script:Default = 0 - } # Desktop + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DesktopLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6079,23 +6075,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}:\Desktop" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DocumentsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6110,23 +6111,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DocumentsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}:\Documents" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DownloadsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6141,23 +6147,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DownloadsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}:\Downloads" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}\Downloads" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $MusicLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6172,23 +6183,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $MusicLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}:\Music" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $PicturesLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6203,23 +6219,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $PicturesLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}:\Pictures" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $VideosLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6234,12 +6255,18 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $VideosLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}:\Videos" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -6247,10 +6274,10 @@ public static string GetString(uint strId) "Custom" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6276,22 +6303,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6317,22 +6343,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6358,22 +6383,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6399,22 +6423,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6440,22 +6463,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6481,13 +6503,12 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -6495,10 +6516,10 @@ public static string GetString(uint strId) "Default" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6513,20 +6534,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6541,20 +6561,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6569,20 +6588,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI } "1" { Write-Verbose -Message $Localization.Skipped -Verbose - Write-Information -MessageData "" -InformationAction Continue } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6597,20 +6615,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6625,24 +6642,21 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved - Write-Information -MessageData "" -InformationAction Continue - $Title = "" $Message = $Localization.UserDefaultFolder -f $VideosLocalizedString $Yes = $Localization.Yes @@ -6655,11 +6669,10 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 index 925d95e7..5db71040 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 @@ -692,7 +692,7 @@ InputMethod -English # InputMethod -Default <# - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu User files or folders won't me moved to a new location. Move them manually They're located in the %USERPROFILE% folder by default @@ -700,7 +700,7 @@ InputMethod -English Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -SetUserShellFolderLocation -Root +Set-UserShellFolderLocation -Root <# Select folders for user folders location manually using a folder browser dialog @@ -711,7 +711,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Custom +# Set-UserShellFolderLocation -Custom <# Change user folders location to the default values @@ -722,7 +722,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Default +# Set-UserShellFolderLocation -Default # Use the latest installed .NET runtime for all apps # Использовать последнюю установленную среду выполнения .NET для всех приложений diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index e1a20b9b..a94ac59f 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -6661,10 +6661,10 @@ function InputMethod <# .SYNOPSIS - User folders location + Change User folders location .PARAMETER Root - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu .PARAMETER Custom Select folders for user folders location manually using a folder browser dialog @@ -6673,13 +6673,13 @@ function InputMethod Change user folders location to the default values .EXAMPLE - SetUserShellFolderLocation -Root + Set-UserShellFolderLocation -Root .EXAMPLE - SetUserShellFolderLocation -Custom + Set-UserShellFolderLocation -Custom .EXAMPLE - SetUserShellFolderLocation -Default + Set-UserShellFolderLocation -Default .NOTES User files or folders won't me moved to a new location @@ -6687,7 +6687,7 @@ function InputMethod .NOTES Current user #> -function SetUserShellFolderLocation +function Set-UserShellFolderLocation { param @@ -6722,7 +6722,7 @@ function SetUserShellFolderLocation The RemoveDesktopINI argument removes desktop.ini in the old user shell folder .EXAMPLE - UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI .LINK https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath @@ -6730,7 +6730,7 @@ function SetUserShellFolderLocation .NOTES User files or folders won't me moved to a new location #> - function UserShellFolder + function Set-UserShellFolder { [CmdletBinding()] param @@ -6754,9 +6754,9 @@ function SetUserShellFolderLocation Redirect user folders to a new location .EXAMPLE - KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" + Set-KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" #> - function KnownFolderPath + function Set-KnownFolderPath { [CmdletBinding()] param @@ -6875,7 +6875,7 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int Remove-Item -Path "$CurrentUserFolderPath\desktop.ini" -Force -ErrorAction Ignore } - KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath + Set-KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUIDs[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force # Save desktop.ini in the UTF-16 LE encoding @@ -7002,26 +7002,22 @@ public static string GetString(uint strId) Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.RetrievingDrivesList -Verbose - # Store all drives letters to use them within ShowMenu function - $DriveLetters = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object) + # Store all fixed disks' letters to use them within ShowMenu function + # https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype?view=net-7.0#fields + $DriveLetters = @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object) # If the number of disks is more than one, set the second drive in the list as default drive if ($DriveLetters.Count -gt 1) { $Script:Default = 1 } - else - { - $Script:Default = 0 - } # Desktop + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DesktopLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7036,23 +7032,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}:\Desktop" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DocumentsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7067,23 +7068,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DocumentsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}:\Documents" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DownloadsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7098,23 +7104,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DownloadsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}:\Downloads" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}\Downloads" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $MusicLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7129,23 +7140,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $MusicLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}:\Music" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $PicturesLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7160,23 +7176,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $PicturesLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}:\Pictures" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $VideosLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7191,12 +7212,18 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $VideosLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}:\Videos" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -7204,10 +7231,10 @@ public static string GetString(uint strId) "Custom" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7233,22 +7260,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7274,22 +7300,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7315,22 +7340,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7356,22 +7380,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7397,22 +7420,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7438,13 +7460,12 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -7452,10 +7473,10 @@ public static string GetString(uint strId) "Default" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7470,20 +7491,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7498,20 +7518,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7526,20 +7545,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI } "1" { Write-Verbose -Message $Localization.Skipped -Verbose - Write-Information -MessageData "" -InformationAction Continue } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7554,20 +7572,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7582,24 +7599,21 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved - Write-Information -MessageData "" -InformationAction Continue - $Title = "" $Message = $Localization.UserDefaultFolder -f $VideosLocalizedString $Yes = $Localization.Yes @@ -7612,11 +7626,10 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 index 22961342..e5b51801 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 @@ -788,7 +788,7 @@ InputMethod -English # InputMethod -Default <# - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu User files or folders won't me moved to a new location. Move them manually They're located in the %USERPROFILE% folder by default @@ -796,7 +796,7 @@ InputMethod -English Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -SetUserShellFolderLocation -Root +Set-UserShellFolderLocation -Root <# Select folders for user folders location manually using a folder browser dialog @@ -807,7 +807,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Custom +# Set-UserShellFolderLocation -Custom <# Change user folders location to the default values @@ -818,7 +818,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Default +# Set-UserShellFolderLocation -Default # Use the latest installed .NET runtime for all apps # Использовать последнюю установленную среду выполнения .NET для всех приложений diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index cec27d5d..468450f6 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -6231,10 +6231,10 @@ function InputMethod <# .SYNOPSIS - User folders location + Change User folders location .PARAMETER Root - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu .PARAMETER Custom Select folders for user folders location manually using a folder browser dialog @@ -6243,13 +6243,13 @@ function InputMethod Change user folders location to the default values .EXAMPLE - SetUserShellFolderLocation -Root + Set-UserShellFolderLocation -Root .EXAMPLE - SetUserShellFolderLocation -Custom + Set-UserShellFolderLocation -Custom .EXAMPLE - SetUserShellFolderLocation -Default + Set-UserShellFolderLocation -Default .NOTES User files or folders won't me moved to a new location @@ -6257,7 +6257,7 @@ function InputMethod .NOTES Current user #> -function SetUserShellFolderLocation +function Set-UserShellFolderLocation { param @@ -6292,7 +6292,7 @@ function SetUserShellFolderLocation The RemoveDesktopINI argument removes desktop.ini in the old user shell folder .EXAMPLE - UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI .LINK https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath @@ -6300,7 +6300,7 @@ function SetUserShellFolderLocation .NOTES User files or folders won't me moved to a new location #> - function UserShellFolder + function Set-UserShellFolder { [CmdletBinding()] param @@ -6324,9 +6324,9 @@ function SetUserShellFolderLocation Redirect user folders to a new location .EXAMPLE - KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" + Set-KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" #> - function KnownFolderPath + function Set-KnownFolderPath { [CmdletBinding()] param @@ -6445,7 +6445,7 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int Remove-Item -Path "$CurrentUserFolderPath\desktop.ini" -Force -ErrorAction Ignore } - KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath + Set-KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUIDs[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force # Save desktop.ini in the UTF-16 LE encoding @@ -6572,26 +6572,22 @@ public static string GetString(uint strId) Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.RetrievingDrivesList -Verbose - # Store all drives letters to use them within ShowMenu function - $DriveLetters = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object) + # Store all fixed disks' letters to use them within ShowMenu function + # https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype?view=net-7.0#fields + $DriveLetters = @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object) # If the number of disks is more than one, set the second drive in the list as default drive if ($DriveLetters.Count -gt 1) { $Script:Default = 1 } - else - { - $Script:Default = 0 - } # Desktop + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DesktopLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6606,23 +6602,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}:\Desktop" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DocumentsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6637,23 +6638,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DocumentsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}:\Documents" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DownloadsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6668,23 +6674,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DownloadsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}:\Downloads" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}\Downloads" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $MusicLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6699,23 +6710,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $MusicLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}:\Music" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $PicturesLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6730,23 +6746,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $PicturesLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}:\Pictures" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $VideosLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6761,12 +6782,18 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $VideosLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}:\Videos" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -6774,10 +6801,10 @@ public static string GetString(uint strId) "Custom" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6803,22 +6830,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6844,22 +6870,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6885,22 +6910,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6926,22 +6950,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6967,22 +6990,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7008,13 +7030,12 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -7022,10 +7043,10 @@ public static string GetString(uint strId) "Default" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7040,20 +7061,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7068,20 +7088,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7096,20 +7115,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI } "1" { Write-Verbose -Message $Localization.Skipped -Verbose - Write-Information -MessageData "" -InformationAction Continue } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7124,20 +7142,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7152,24 +7169,21 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved - Write-Information -MessageData "" -InformationAction Continue - $Title = "" $Message = $Localization.UserDefaultFolder -f $VideosLocalizedString $Yes = $Localization.Yes @@ -7182,11 +7196,10 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } diff --git a/src/Sophia_Script_for_Windows_11/Sophia.ps1 b/src/Sophia_Script_for_Windows_11/Sophia.ps1 index d5ffb808..bee3054c 100644 --- a/src/Sophia_Script_for_Windows_11/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11/Sophia.ps1 @@ -726,7 +726,7 @@ InputMethod -English # InputMethod -Default <# - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu User files or folders won't me moved to a new location. Move them manually They're located in the %USERPROFILE% folder by default @@ -734,7 +734,7 @@ InputMethod -English Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -SetUserShellFolderLocation -Root +Set-UserShellFolderLocation -Root <# Select folders for user folders location manually using a folder browser dialog @@ -745,7 +745,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Custom +# Set-UserShellFolderLocation -Custom <# Change user folders location to the default values @@ -756,7 +756,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Default +# Set-UserShellFolderLocation -Default # Use the latest installed .NET runtime for all apps # Использовать последнюю установленную среду выполнения .NET для всех приложений diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index a55ed226..932a9783 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -6231,10 +6231,10 @@ function InputMethod <# .SYNOPSIS - User folders location + Change User folders location .PARAMETER Root - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu .PARAMETER Custom Select folders for user folders location manually using a folder browser dialog @@ -6243,13 +6243,13 @@ function InputMethod Change user folders location to the default values .EXAMPLE - SetUserShellFolderLocation -Root + Set-UserShellFolderLocation -Root .EXAMPLE - SetUserShellFolderLocation -Custom + Set-UserShellFolderLocation -Custom .EXAMPLE - SetUserShellFolderLocation -Default + Set-UserShellFolderLocation -Default .NOTES User files or folders won't me moved to a new location @@ -6257,7 +6257,7 @@ function InputMethod .NOTES Current user #> -function SetUserShellFolderLocation +function Set-UserShellFolderLocation { param @@ -6292,7 +6292,7 @@ function SetUserShellFolderLocation The RemoveDesktopINI argument removes desktop.ini in the old user shell folder .EXAMPLE - UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI .LINK https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath @@ -6300,7 +6300,7 @@ function SetUserShellFolderLocation .NOTES User files or folders won't me moved to a new location #> - function UserShellFolder + function Set-UserShellFolder { [CmdletBinding()] param @@ -6324,9 +6324,9 @@ function SetUserShellFolderLocation Redirect user folders to a new location .EXAMPLE - KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" + Set-KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop" #> - function KnownFolderPath + function Set-KnownFolderPath { [CmdletBinding()] param @@ -6445,7 +6445,7 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int Remove-Item -Path "$CurrentUserFolderPath\desktop.ini" -Force -ErrorAction Ignore } - KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath + Set-KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUIDs[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force # Save desktop.ini in the UTF-16 LE encoding @@ -6572,26 +6572,22 @@ public static string GetString(uint strId) Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.RetrievingDrivesList -Verbose - # Store all drives letters to use them within ShowMenu function - $DriveLetters = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object) + # Store all fixed disks' letters to use them within ShowMenu function + # https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype?view=net-7.0#fields + $DriveLetters = @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object) # If the number of disks is more than one, set the second drive in the list as default drive if ($DriveLetters.Count -gt 1) { $Script:Default = 1 } - else - { - $Script:Default = 0 - } # Desktop + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DesktopLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6606,23 +6602,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}:\Desktop" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DocumentsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6637,23 +6638,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DocumentsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}:\Documents" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $DownloadsLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6668,23 +6674,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DownloadsLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}:\Downloads" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}\Downloads" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $MusicLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6699,23 +6710,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $MusicLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}:\Music" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $PicturesLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6730,23 +6746,28 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $PicturesLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}:\Pictures" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.DriveSelect -f $VideosLocalizedString) -Verbose $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6761,12 +6782,18 @@ public static string GetString(uint strId) { "0" { - $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $VideosLocalizedString) -Menu $DriveLetters -Default $Script:Default - UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}:\Videos" -RemoveDesktopINI + if ($DriveLetters.Count -gt 1) + { + $SelectedDrive = ShowMenu -Title ($Localization.DriveSelect -f $DesktopLocalizedString) -Menu $DriveLetters -Default $Script:Default + } + else + { + $SelectedDrive = $env:SystemDrive + } + Set-UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -6774,10 +6801,10 @@ public static string GetString(uint strId) "Custom" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6803,22 +6830,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6844,22 +6870,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6885,22 +6910,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6926,22 +6950,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -6967,22 +6990,21 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7008,13 +7030,12 @@ public static string GetString(uint strId) if ($FolderBrowserDialog.SelectedPath) { - UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose } } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } @@ -7022,10 +7043,10 @@ public static string GetString(uint strId) "Default" { # Desktop + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DesktopLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7040,20 +7061,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Documents + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DocumentsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7068,20 +7088,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Downloads + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $DownloadsLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7096,20 +7115,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI } "1" { Write-Verbose -Message $Localization.Skipped -Verbose - Write-Information -MessageData "" -InformationAction Continue } } # Music + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $MusicLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7124,20 +7142,19 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Pictures + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $PicturesLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved $Title = "" @@ -7152,24 +7169,21 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } # Videos + Write-Information -MessageData "" -InformationAction Continue $CurrentUserFolderLocation = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" - Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose - Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.CurrentUserFolderLocation -f $VideosLocalizedString, $CurrentUserFolderLocation) -Verbose Write-Warning -Message $Localization.FilesWontBeMoved - Write-Information -MessageData "" -InformationAction Continue - $Title = "" $Message = $Localization.UserDefaultFolder -f $VideosLocalizedString $Yes = $Localization.Yes @@ -7182,11 +7196,10 @@ public static string GetString(uint strId) { "0" { - UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI + Set-UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI } "1" { - Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message $Localization.Skipped -Verbose } } diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 index 4f936c77..35e91fad 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 @@ -735,7 +735,7 @@ InputMethod -English # InputMethod -Default <# - Move user folders location to the root of any drive using the interactive menu + Change user folders location to the root of any drive using the interactive menu User files or folders won't me moved to a new location. Move them manually They're located in the %USERPROFILE% folder by default @@ -743,7 +743,7 @@ InputMethod -English Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -SetUserShellFolderLocation -Root +Set-UserShellFolderLocation -Root <# Select folders for user folders location manually using a folder browser dialog @@ -754,7 +754,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Custom +# Set-UserShellFolderLocation -Custom <# Change user folders location to the default values @@ -765,7 +765,7 @@ SetUserShellFolderLocation -Root Пользовательские файлы и папки не будут перемещены в новое расположение. Переместите их вручную По умолчанию они располагаются в папке %USERPROFILE% #> -# SetUserShellFolderLocation -Default +# Set-UserShellFolderLocation -Default # Use the latest installed .NET runtime for all apps # Использовать последнюю установленную среду выполнения .NET для всех приложений