It does not work in a shortcut, CMD script, and Command Prompt,
Weird. I tested as both shortcut target & from Command Prrompt and both worked.
Does the shell restart but folders don't re-open or is nothing happening...
If the shell is restarting , but folders not re-opening:
Try modifying the command to:
Code:
powershell.exe -NoExit -NoLogo -NoProfile -file
That should leave a PowerShell window open, but the code executes before it dispalys a prompt, but your variable should still be defined.
First check to see if $SavedFolderInfo looks right with $SavedFolderInfo | fl
:
Code:
PS C:\WINDOWS\System32\WindowsPowerShell\v1.0> $SavedFolderInfo | fl
IsFileSystem : False
FolderItemPath : ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
NameSpacePath : This PC
IsFileSystem : True
FolderItemPath : C:\Users\keith\Documents
NameSpacePath : This PC\Documents
IsFileSystem : True
FolderItemPath : C:\Users\keith\Pictures
NameSpacePath : This PC\Pictures
IsFileSystem : True
FolderItemPath : C:\Users\Keith\Sandbox\Shell ReStart with Window Resstoration
NameSpacePath : Sandbox\Shell ReStart with Window Resstoration
VErify that the shell object is still defined with $Shell
:
Code:
PS C:\WINDOWS\System32\WindowsPowerShell\v1.0> $Shell
Application Parent
----------- ------
System.__ComObject System.__ComObject
If those items are still defined, paste the re-open portion of the code into the window & press Enter:
Code:
PS C:\WINDOWS\System32\WindowsPowerShell\v1.0> $SavedFolderInfo | %{
>> If ( $_.IsFileSystem ) {
>> Open-NSFolder $oDesktop $_.NameSpacePath
>> } Else {
>> $Shell.Open( ($_.FolderItemPath -replace ('^::','Shell:::')) )
>> }
>> }
>>
PS C:\WINDOWS\System32\WindowsPowerShell\v1.0>
It could be the code getting ahead of events. The version I'm working on now, which will restored Search results and (opefully) size, position, and state ( windowed, minimized, maximized, FullScreen ), also has code that attempts to time it out better.
But if repeating the re-open code sequence sucessfully opened the folders, the situation might be remidied with a pause after the shell restart. That would be accomplished by adding the command Start-Sleep 5 ( 5-second wait ) after the shell restart & before the re-open sequence:
Code:
...
...
$oDesktop = $Shell.NameSpace("shell:Desktop")
Start-Sleep 5
$SavedFolderInfo | %{
...
...
If that helps, you can trim the timeout value down until things go haywire a litttle, then bump it back up,