Restart explorer.exe Process in Windows 10  

Page 6 of 7 FirstFirst ... 4567 LastLast

  1. Posts : 7,606
    Windows 10 Home 20H2
       #50

    KeithM said:
    Code:
    . 'D:\KeithM.ps1'
    If I recall correctly, I have not disabled "running scripts", as I run scripts every day.
    Code:
    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Try the new cross-platform PowerShell https://aka.ms/pscore6
    
    PS C:\Users\Matthew_Wai> . 'D:\KeithM.ps1'
    . : File D:\KeithM.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see
    about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
    At line:1 char:3
    + . 'D:\KeithM.ps1'
    +   ~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [], PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess
    PS C:\Users\Matthew_Wai>
      My Computer


  2. Posts : 989
    Microsoft Windows 10 Home
       #51

    Matthew Wai said:
    If I recall correctly, I have not disabled "running scripts", as I run scripts every day.
    Code:
    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Try the new cross-platform PowerShell https://aka.ms/pscore6
    
    PS C:\Users\Matthew_Wai> . 'D:\KeithM.ps1'
    . : File D:\KeithM.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see
    about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
    At line:1 char:3
    + . 'D:\KeithM.ps1'
    +   ~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [], PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess
    PS C:\Users\Matthew_Wai>


    Use Get-ExecutionPolicy to retrieve the execution policy for your local machine:

    Code:
    PS C:\...\keith>Get-ExecutionPolicy
    RemoteSigned
    PS C:\...\keith>
    Most likely yours is Restricted. If so, execute the command:
    Code:
    Set-ExecutionPolicy RemoteSigned
    and verify with Get-ExecutionPolicy.

    Now try the dot-sourcing again.
      My Computer


  3. Posts : 7,606
    Windows 10 Home 20H2
       #52

    KeithM said:
    Now try the dot-sourcing again.
    . 'D:\KeithM.ps1' works.
      My Computer


  4. Posts : 989
    Microsoft Windows 10 Home
       #53

    Matthew Wai said:
    . 'D:\KeithM.ps1' works.
    Then it should work when invoked with:
    Code:
    powershell.exe -NoLogo -NoProfile -NonInteractive -WindowStyle Hidden  -file 'D:\KeithM.ps1'
    as the target of a shortcut or context menu command.

    I'm not sure about the wrapping wiht wbscript as I don't mind hte window flasth ( that is why people do that, right? ). Especially with re-staring the shell --- there's going to be a flash anyway.
      My Computer


  5. Posts : 7,606
    Windows 10 Home 20H2
       #54

    KeithM said:
    Code:
    powershell.exe -NoLogo -NoProfile -NonInteractive -WindowStyle Hidden  -file 'D:\KeithM.ps1'
    It does not work in a shortcut, CMD script, and Command Prompt,
      My Computer


  6. Posts : 989
    Microsoft Windows 10 Home
       #55

    Matthew Wai said:
    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,
      My Computer


  7. Posts : 7,606
    Windows 10 Home 20H2
       #56

    @KeithM, the following target works.

    PowerShell -file "D:\KeithM.ps1"

    It works also on Command Prompt and in a CMD script.
      My Computer


  8. Posts : 989
    Microsoft Windows 10 Home
       #57

    Matthew Wai said:
    @KeithM, the following target works.

    PowerShell -file "D:\KeithM.ps1"

    It works also on Command Prompt and in a CMD script.
    Interesting. If you have the time, can you test to see which of the parameters in the earlier command interferd with execution? I need all the info I can gather on the behavior on other systems.
      My Computer


  9. Posts : 7,606
    Windows 10 Home 20H2
       #58

    @KeithM

    PowerShell -NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -file "D:\KeithM.ps1"

    The above works on Command Prompt, while the following does not.

    PowerShell -NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -file 'D:\KeithM.ps1'
      My Computer


  10. Posts : 519
    Win7 Pro X64, Win10 Pro x640
       #59

    Sorry for the delay but I am not just getting back to looking at this thread....

    I tested out @KeithM Option 1 and Option 2 scripts and both seem to work. Both scripts re-open all file explorer windows opened prior to closing. It seems that if some windows are open on Monitor 2 initially, for example, then the open all stacked on Monitor 1 after the script is run.

    What exactly is the Namespace and is that Option 2 code relevant?

    The post also mentioned figuring out how to reopen libraries and search folders. Was that incorporated into the later scripts?

    Thanks!
      My Computer


 

Tutorial Categories

Restart explorer.exe Process in Windows 10 Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:15.
Find Us




Windows 10 Forums