How to open 'This PC' using CMD or Powershell? - windows

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

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.

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'"

You can use this in cmd:
Explorer /root,

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.

Open the Command Prompt and type this in:
explorer =

Related

explorer command doesn't work in pwsh / Windows Powershell after upgrade to Windows 11

In situations where I need to quickly switch from Powershell to the Windows Explorer, I used to be able to launch Windows Explorer from whatever directory I happened to be in, like this:
PS > explorer .
(This is really just calling C:\Windows\explorer.exe.)
It worked fine until upgrading to Windows 11. Now it silently fails to do anything.
I've confirmed that, even while using the new Terminal app, the command still works in the Command Prompt. And in pwsh, the explorer alias is still pointing at C:\Windows\explorer.exe.
So why is it now broken in Powershell? And is there any work-around?
PS: I have confirmed that the following do not work either:
PS > & explorer . # Nothing
PS > C:\Windows\explorer.exe . # Nada
PS > & C:\Windows\explorer.exe . # Zilch
This is just a workaround, but as you confirmed it working, I'll turn it into an answer:
$shell = New-Object -ComObject Shell.Application
$shell.Open( $PWD.ProviderPath )
# Also works:
# $shell.Explore( $PWD.ProviderPath )
Create an instance of the Shell COM object and then call its methods Open or Explore to open the current directory, obtained from automatic variable $PWD, in Explorer.
As mklement0 points out, we have to use $PWD.ProviderPath as $PWD.Path may be based on a PowerShell-only drive, which external programs such as File Explorer don't know about.
You might also want to check the type of the provider to make sure you call the above code only for filesystem paths:
# As a demonstration, let $PWD point to a registry location
Set-Location HKCU:\Software
# The following if branch won't be entered
if( $PWD.Provider.Name -eq 'FileSystem' ) { ... }

Detecting if a program is installed and where using cmd.exe

Windows has the program start.exe which somehow knows how to open programs by their lay-name like "firefox"
Typing start firefox into cmd.exe opens firefox assuming its installed.
Is there a similar command to start that will return the file path rather than starting the application?
Also open to any similar but proper solution
UPDATE:
Other answers suggest using where command, and this works for programs like ping which are in the system directories, but does not find firefox like start does.
Take a look at this registry key.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
In it you will find something similar to this for firefox.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe]
#="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"
"Path"="C:\\Program Files (x86)\\Mozilla Firefox"
and here is a bit that reads the value from Powershell. Same thing can be done from batch file with reg.exe.
$Firepath = get-item -path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe'
$Firepath.GetValue('')
wmic product get name,version /format:csv > C:\testappu\Computername%.csv

Locate a desktop shortcut with the command prompt or Powershell

I'm trying to use the command prompt or Powershell to locate some of the shortcuts that an installed program has created on my desktop. For Example, Adobe Reader has created a shortcut on my desktop. I try to use dir "c:\Users\MyUserName\Desktop", but I do not see this shortcut.
How can I find this shortcut through a command prompt or with powershell?
Shortcuts are files with extension ".lnk" and would be displayed by dir ( cmd and powershell)
I think some shortcuts (.lnk files) are created at c:\users\public\Desktop so that they can be shared by all users. ( shortcuts placed in this location are available on the desktop of all the users)
More about the "Public user" here: http://windows.microsoft.com/en-US/windows-vista/Sharing-files-with-the-Public-folder
So you may want to look in that location as well.

How to change the path of a mapped drive in win7?

Now it's mapped to \\192.168.248.128,how to change it to \\192.168.66.2 instead?
If you want to use the command line have a look to the next answer below!
But you can also edit the settings in Windows Registry: 'HKEY_CURRENT_USER\Network\[Drive letter]'
When you now open a new 'My Computer' window - after changing the target in registry - you will likely see the old settings, but that is only a visual problem. Try to open the entry, and it should work!
Have a look to Chris Budys interesting comment below, that fixes obviously the visual problem.
net use can modify a drive in place without deleting and recreating. You simply execute the command as if you're mapping a new drive, and it replaces it instead. The command syntax is:
net use [Drive name] [UNC path]
Example:
C:\> net use U: \\192.168.66.2
U: has a remembered connection to \\192.168.248.128. Do you
want to overwrite the remembered connection? (Y/N) [Y]: y
The command completed successfully.
You can create another mapped network drive:
right-click the current drive and click "Disconnect"
right-click "Computer" and select Map Network Drive
configure the new drive
If you want Windows API you can use WNetAddConnection2.
If you want a BAT (command line) you can try net use command line option.

File Access takes me to command prompt rather than Explorer

Whenever I go to my command prompt and type a "c:\temp" or any other file/directory, it takes me to the command prompt rather than the file explorer. Can somebody please tell me how I can fix this so that all file/directory access from cmd takes me to the file explorer.
I have a Win2k3 64bit machine. Has this got anything to do with the 32bit/64bit explorer ?
To run Windows Explorer from command prompt you must type name of the executable:
explorer.exe
or just
explorer
To open a certain folder, pass the path as an arguments. Details here:
Command-Line Switches for Windows Explorer (MSDN KB)
See examples.
To open Explorer at the directory where your cmd is operating you can use
start .
and at a parent directory you can use
start ..

Resources