.bat file to restart explorer.exe sometimes fail

Page 6 of 6 FirstFirst ... 456

  1. Posts : 181
    10, server 2016, server2012
    Thread Starter
       #51

    KeithM said:
    Control Panel > All Control Panel Items > System

    Click the Advanced System Settings link found near the upper-left corner

    Click the Environmetal Variables... button

    Select Path in the System Variables section and select Edit
    Attachment 304144

    Looking at my Edit dialog, it appears that C:WINDOWS is in my path via the %SystemRoot% entry. Verify that is defined by typing env:SystemRoot in PowerShell. If %SystemRoot% is difined, I would try adding that to your path.

    Attachment 304145
    do i need restart after editing variables? after I added c:\windows or %systemroot% and then use $env:path -split ';'

    c windows still not showing up.


    edit: its working now with
    Code:
    $Shell = New-Object -ComObject shell.application
    $SavedPaths = ( $Shell.Windows() | select -expand LocationURL )
    Get-Process explorer | Stop-Process
    $SavedPaths | ForEach { explorer $_ }
    


    issue is after restarting explorer it requires user to press enter to execute the last line "
    $SavedPaths | ForEach { explorer $_ }" in order to open up previous folders. how can we get it enter that line automatically?
      My Computer


  2. Posts : 989
    Microsoft Windows 10 Home
       #52

    You at least need a new PowerShell session. But in updatoing System variables, I would reStart.
      My Computer


  3. Posts : 181
    10, server 2016, server2012
    Thread Starter
       #53

    KeithM said:
    You at least need a new PowerShell session. But in updatoing System variables, I would reStart.
    yea i restarted and the variables sticked after the restart.

    how can I get the last line of the codes $SavedPaths | ForEach { explorer $_ } to enter automatically?

    currently I run the .ps file, it restart explorer and stuck at last line requires manual enter, and also requires manual closing the ps window. would the cmd command to close work for ps window too?
      My Computer


  4. Posts : 989
    Microsoft Windows 10 Home
       #54

    ...stuck at last line requires manual enter...
    You don't still have a Read-Host Pause in your code, do you?


    Have you verified that explorer now works as a command in PowerShell​?

    What sort of behavior/functionality are you looking for???
      My Computer


  5. Posts : 181
    10, server 2016, server2012
    Thread Starter
       #55

    KeithM said:
    You don't still have a Read-Host Pause in your code, do you?


    Have you verified that explorer now works as a command in PowerShell​?

    What sort of behavior/functionality are you looking for???
    explorer now works in PS, thats after i added variable and restarted now it works.

    read-host pause isn't there, but I will try add it after restart explorer line

    fucntion basically to restart explorer, restore folder sessions automatically and then closes the powershell window on its own. most of my .bat cmd i made it so they close too after it is executed instead of staying open.
      My Computer


  6. Posts : 989
    Microsoft Windows 10 Home
       #56

    You don't need to add Read-Host, I thought that might be the "hang " you were talking about.

    What is displayed in the PS console when you're refquired to press Enter?


    If you right-click a .ps1 script in Explorer & select Run with PowerShell, it should execute & close.
      My Computer


  7. Posts : 181
    10, server 2016, server2012
    Thread Starter
       #57

    KeithM said:
    You don't need to add Read-Host, I thought that might be the "hang " you were talking about.
    What is displayed in the PS console when you're refquired to press Enter?
    If you right-click a .ps1 script in Explorer & select Run with PowerShell, it should execute & close.
    I wish I can thank multiple times on forum but i can't.

    it is working and window auto closes itself now, I think reason it wasn't closing and requires manual enter on the last line of codes was because I had run in a powershell window and manually paste the codes into it, instead of doing it through ps1.

    running ps1 worked and its all good, thanks so much, this is so much more convenient than to navigate to all the folder paths and reopen 5-10 folders everytime explorer crashes. ty for sharing this, hope more people able to come across this thread.
      My Computer


  8. Posts : 989
    Microsoft Windows 10 Home
       #58

    You're welcome. Glad it's all working.
      My Computer


  9. Posts : 181
    10, server 2016, server2012
    Thread Starter
       #59

    KeithM said:
    You're welcome. Glad it's all working.
    hey Keith, sorry to bump such an old thread.

    a question in regards to restarting explorer, is there a way for window to remember the order of tabs prior restarting and show them in order when explorer.exe is restarted?
      My Computer


 

  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 22:16.
Find Us




Windows 10 Forums