New
#41
Let's start with some obvious troubleshooting:
- In PowerShell, does the command
explorer
open Explorer to its default? (This PC or Quick Access)- Does the command
explorer c:\Users
open the Users folder?- 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.
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 $_ }
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>
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?
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
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
Not sure. The firt thing I would check is your Path environmental varable with the statement$env:path -split ';'
:
Make sureCode:>$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\ ...C:\WINDOWS
is there.
But to get your code running, try substitutingStart-Process
forexplorer
:
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
Control Panel > All Control Panel Items > System
Click theAdvanced System Settings
link found near the upper-left corner
Click theEnvironmetal Variables...
button
Select Path in the System Variables section and select Edit
Looking at my Edit dialog, it appears thatC:WINDOWS
is in my path via the%SystemRoot%
entry. Verify that is defined by typingenv:SystemRoot
in PowerShell. If%SystemRoot%
is difined, I would try adding that to your path.