Reputation: 103
I need a way of opening the explorer at This PC , in the same way as opening in a windows explorer Gui, but I am incapable of this as using Explorer.exe in CMD opens quick access.
I tried opening it with a shortcut and that too failed.
Does anyone know of a way to do this?
Cheers
Upvotes: 10
Views: 29392
Reputation: 22283
explorer shell:MyComputerFolder
Other folders are available as well (the entire list is available at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\FolderDescriptions
, see Name
values)
Reference: https://www.winhelponline.com/blog/shell-commands-to-access-the-special-folders/
Credit: https://stackoverflow.com/a/63436479/355438
Upvotes: 1
Reputation: 66
All of this comment uses Powershell 7, idk if it works on Windows Powershell 5.1. and ofc it's using Windows Terminal:
For documentation purposes mainly, you can skip to the next Header (-->next h2)
$shell = New-Object -ComObject Shell.Application
$thisPCFolder = $shell.Namespace(0x11)
(0x11) is same as 20D04FE0-3AEA-1069-A2D8-08002B30309D
so the second line is the same as
$thisPCFolder = $shell.NameSpace('::{20D04FE0-3AEA-1069-A2D8-08002B30309D}')
use whichever.
Take into account that This PC
isn't an actual folder, it's a virtual one, so for that you have to use Shell.Application COM objects.
The Shell.Application COM object
uses these numeric representations to access specific special folders and namespaces in the Windows Shell. Which is the first block code.
So 0x11
isn't the only one who works these constants Windows Shell API and can be found in the Shlobj.h
header file, which is a part of the Windows Software Development Kit (SDK)
. Like these constants:
So you don't have to download any module or anything, you just need to have Powershell 7 and you should be good to execute the code on your machine.
So to enumerate the disks I did this:
# Create a new instance of Shell.Application
$shell = New-Object -ComObject Shell.Application
# Get the "This PC" folder
$thisPCFolder = $shell.Namespace(0x11)
# Enumerate through the items in "This PC" folder
foreach ($item in $thisPCFolder.Items()) {
# Display the name and path of each item
$name = $thisPCFolder.GetDetailsOf($item, 0)
$path = $thisPCFolder.GetDetailsOf($item, 217)
Write-Output "$name : $path"
}
printing this on my Terminal when I execute it:
Local Disk (C:) :
name_of_your_disk_D (D:) :
you can skip this
As an example of usage on real code application you can read this and see how 0x11
is used github code file on line 40
currently
........
Or you can just use Start-Process C:\
or Start-Process D:\
if you know already the name of your disk and then press Alt + ↑
But the answer you might really want is this, copy paste this block code on your PowerShell and see what happens:
# Use the Start-Process cmdlet to open "This PC" (My Computer) in Windows Explorer
Start-Process "explorer.exe" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
Now you could use an Alias for this last block code and then put it on $PROFILE so it applies to your shell each time you open it and not only one session. This how to do so:
Test-Path $PROFILE
False
you need to create a file, run:New-Item -ItemType File -Path $PROFILE -Force
notepad.exe $PROFILE
function MyPC {
Start-Process "explorer.exe" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
}
. $PROFILE
Now each time you use MyPC
alias in your PowerShell 7 terminal it will open This PC
in a new Windows Explorer window.
edit: so i just read the above answer (the most voted one on here) so basically you could just go to Folder options
and change from Home
to This PC
and then just write explorer
on your PowerShell and it will lead you to This PC
.
sources: https://www.elevenforum.com/t/list-of-windows-11-clsid-key-guid-shortcuts.1075/
Upvotes: 1
Reputation: 21418
Just like you can run explorer.exe C:\
to open up the C:
(or any other drive or folder path), you can also use a file:
URI to open paths in Explorer as well. If you just specify the file:
protocol without a directory (or specify file:\\
), it will open This PC
:
explorer file:
explorer file:\\
Note that you can also change the default Explorer location from Quick Access
to This PC
as well from Folder Options
:
You can set this in the registry too if you're after automation to configure this. See my answer on how you can use PowerShell to set the default launch folder in the registry.
Upvotes: 19
Reputation: 8741
On Powershell, we can do this:
(New-Object -ComObject Shell.Application).Namespace("").Self.InvokeVerb()
We create a com object of class Shell.Application, then call .InvokeVerb() that invokes the default verb "open".
Or more rigourously, by defining ssfDRIVES constant (see Microsoft reference)
Set-Variable ssfDRIVES -Option Constant -Value 0x11
(New-Object -ComObject Shell.Application).Namespace($ssfDRIVES).Self.InvokeVerb()
ssfDRIVES 0x11 (17). Namespace points to My Computer—the virtual folder that contains everything on the local computer: storage devices, printers, and Control Panel. This folder can also contain mapped network drives.
Upvotes: 2
Reputation: 38613
My experience is that, the following should work:
From cmd:
Start "" "%SystemRoot%\explorer.exe" /Select,"This PC"
From powershell:
Start "$Env:SystemRoot\explorer.exe" "/Select,'This PC'"
Upvotes: 4