.bat file to restart explorer.exe sometimes fail

Page 5 of 6 FirstFirst ... 3456 LastLast

  1. Posts : 188
    10, server 2016, server2012
    Thread Starter
       #41

    Try3 said:
    This is of no help to you at all but I've compared what you are using with what I'm using and they are exactly the same.

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

    I have also run them by pasting those commands into a PowerShell window - as shown, there are no error responses.
    Code:
    PS C:\Users\Denis> $Shell = New-Object -ComObject shell.application
    PS C:\Users\Denis> $SavedPaths = ( $Shell.Windows() | select -expand LocationURL )
    PS C:\Users\Denis> Get-Process explorer | Stop-Process
    PS C:\Users\Denis> $SavedPaths | ForEach { explorer $_ }
    PS C:\Users\Denis>

    As you noted above, it works for me [both as a ps1 file & as a set of commands in the PS window]. My FE folders get reopened afterwards

    Denis
    I see, alright thanks for hleping me check. I tried running from ps1 script and it also did the same, no folders were restored.

    im guessing is because im accessing C drive or D drive from under "My computer" thats just how window explorer open its folder.

    .bat file to restart explorer.exe sometimes fail-fs.png

    what does your show?
      My Computer


  2. Posts : 989
    Microsoft Windows 10 Home
       #42

    m18xr2 said:
    I see, alright thanks for hleping me check. I tried running from ps1 script and it also did the same, no folders were restored.

    im guessing is because im accessing C drive or D drive from under "My computer" thats just how window explorer open its folder.

    .bat file to restart explorer.exe sometimes fail-fs.png

    what does your show?
    Let's start with some obvious troubleshooting:
    1. In PowerShell, does the command explorer open Explorer to its default? (This PC or Quick Access)
    2. Does the command explorer c:\Users open the Users folder?
    3. Now test using the LocationURL format: explorer file:///c:\Users


    If those check out, let's double-check that the shell is restarting automatically by running: Get-Process explorer | Stop-Process

    If that seems fine, let's add some confirmation messages and pauses to the code. When "Pause:" is displayed in the PowerShell window, execution is paused until you press enter.


    Code:
    $Shell = New-Object -ComObject shell.application
    $SavedPaths = ( $Shell.Windows() | select -expand LocationURL ) -ne ''
    echo ( 'Path Count: ' + $SavedPaths.Count )
    echo ( $SavedPaths | Out-String )
    Read-Host Pause
    Get-Process explorer | Stop-Process
    Read-Host Pause
    $SavedPaths | ForEach {
        echo "explorer $_"
        explorer $_    
    }
    Post a screenshot of the PowerShell window or copy & paste the output inot your reply.

    Code:
    $Shell = New-Object -ComObject shell.application
    >> $SavedPaths = ( $Shell.Windows() | select -expand LocationURL ) -ne ''
    >> echo ( 'Path Count: ' + $SavedPaths.Count )
    >> echo ( $SavedPaths | Out-String )
    >> Read-Host Pause
    >> Get-Process explorer | Stop-Process
    >> Read-Host Pause
    >> $SavedPaths | ForEach {
    >>     echo "explorer $_"
    >>     explorer $_
    >> }
    Path Count: 3
    file:///C:/Users/keith/Downloads
    file:///C:/Users/keith/Desktop
    file:///C:/Users/keith/Documents
    
    Pause:
    
    Pause:
    
    explorer file:///C:/Users/keith/Downloads
    explorer file:///C:/Users/keith/Desktop
    explorer file:///C:/Users/keith/Documents
    PS C:\...\3d>
      My Computer


  3. Posts : 188
    10, server 2016, server2012
    Thread Starter
       #43

    KeithM said:
    Let's start with some obvious troubleshooting:
    1. In PowerShell, does the command explorer open Explorer to its default? (This PC or Quick Access)
    2. Does the command explorer c:\Users open the Users folder?
    3. Now test using the LocationURL format: explorer file:///c:\Users

    If those check out, let's double-check that the shell is restarting automatically by running: Get-Process explorer | Stop-Process
    If that seems fine, let's add some confirmation messages and pauses to the code. When "Pause:" is displayed in the PowerShell window, execution is paused until you press enter.
    I think you found the culprit with one test at a time.

    Get-Process explorer | Stop-Process does infact restart explorer.exe BUT
    In PowerShell, command Explorer or explorer c:\Users do not work for me. when input in powershell with those two, it says "the term explorer is not recognized as a cmdlet, function etc...."

    how can i fix this?
      My Computer


  4. Posts : 16,972
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #44

    Does the PowerShell window provide any error message or does it just pass on as if everything was alright?
    Code:
    PS D:\> Explorer                                                                                                        
    PS D:\> explorer c:\Users                                                                                               
    PS D:\>

    Does the command explorer work alright if you put it in the Run dialog [Right-click on Start button, Run]

    Denis
      My Computer


  5. Posts : 188
    10, server 2016, server2012
    Thread Starter
       #45

    Try3 said:
    Does the PowerShell window provide any error message or does it just pass on as if everything was alright?
    Code:
    PS D:\> Explorer                                                                                                        
    PS D:\> explorer c:\Users                                                                                               
    PS D:\>

    Does the command explorer work alright if you put it in the Run dialog [Right-click on Start button, Run]

    Denis
    in run it works fine. just not in powershell saying its not a recognized command or name
      My Computer


  6. Posts : 16,972
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #46

    Understood. [And I'm sorry, you had already said what the error message was.]

    You'll need to wait for Keith then.

    Best of luck,
    Denis
      My Computer


  7. Posts : 989
    Microsoft Windows 10 Home
       #47

    m18xr2 said:
    I think you found the culprit with one test at a time.

    Get-Process explorer | Stop-Process does infact restart explorer.exe BUT
    In PowerShell, command Explorer or explorer c:\Users do not work for me. when input in powershell with those two, it says "the term explorer is not recognized as a cmdlet, function etc...."

    how can i fix this?
    Not sure. The firt thing I would check is your Path environmental varable with the statement $env:path -split ';':

    Code:
    >$env:path -split ';'
    C:\Program Files (x86)\Intel\iCLS Client\
    C:\Program Files\Intel\iCLS Client\
    C:\WINDOWS\system32
    C:\WINDOWS
    C:\WINDOWS\System32\Wbem
    C:\WINDOWS\System32\WindowsPowerShell\v1.0\
    
    ...
    Make sure C:\WINDOWS is there.

    But to get your code running, try substituting Start-Process for explorer:

    Code:
    $SavedPaths = ( $Shell.Windows() | select -expand LocationURL )
    Get-Process explorer | Stop-Process
    $SavedPaths | ForEach { Start-Process $_ }
      My Computer


  8. Posts : 188
    10, server 2016, server2012
    Thread Starter
       #48

    KeithM said:
    Not sure. The firt thing I would check is your Path environmental varable with the statement $env:path -split ';':

    Code:
    >$env:path -split ';'
    C:\Program Files (x86)\Intel\iCLS Client\
    C:\Program Files\Intel\iCLS Client\
    C:\WINDOWS\system32
    C:\WINDOWS
    C:\WINDOWS\System32\Wbem
    C:\WINDOWS\System32\WindowsPowerShell\v1.0\
    
    ...
    Make sure C:\WINDOWS is there.

    But to get your code running, try substituting Start-Process for explorer:

    Code:
    $SavedPaths = ( $Shell.Windows() | select -expand LocationURL )
    Get-Process explorer | Stop-Process
    $SavedPaths | ForEach { Start-Process $_ }
    these are the variables I have

    C:\ProgramData\Oracle\Java\javapath
    C:\windows\system32
    C:\Windows\System32\WindowsPowerShell\v1.0
    C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common

    im not even sure why java is there. how can I add c:\windows to the environment variable and remove unwanted ones like java
      My Computer


  9. Posts : 989
    Microsoft Windows 10 Home
       #49

    m18xr2 said:
    these are the variables I have

    C:\ProgramData\Oracle\Java\javapath
    C:\windows\system32
    C:\Windows\System32\WindowsPowerShell\v1.0
    C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common

    im not even sure why java is there. how can I add c:\windows to the environment variable and remove unwanted ones like java
    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
    .bat file to restart explorer.exe sometimes fail-screenshot-872-.png

    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.

    .bat file to restart explorer.exe sometimes fail-screenshot-873-.png
      My Computer


  10. Posts : 919
    Windows 10 Pro 64bit 22H2 19045.3324
       #50

    KeithM said:
    Control Panel > All Control Panel Items > System
    Just a heads up, not sure what version @m18xr2 is running but 20H2 Control Panel > System now takes you here. The Advanced settings, a link at the bottom.

    .bat file to restart explorer.exe sometimes fail-newsystemforoldcontrolpanel.jpg
      My Computers


 

  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 02:45.
Find Us




Windows 10 Forums