How to open an explorer window from the command prompt’s current directory

Account Information

Share with Your Friends

How to move the taskbar to the top of the display in Windows 11

How to move the taskbar to the top of the display in Windows 11

Microsoft does not make Windows 11 personalization as easy as it could. To move the taskbar to the top of your screen you will have to perform a deep edit of the Registry File.

While there are dozens of official personalization settings in Microsoft Windows 11, there are still a few personalization tricks that remain elusive and hidden from the typical user. To mold and manipulate Windows 11 into the operating system you would like it to be, sometimes you must be willing to take some calculated risks.

Must-read Windows coverage

  • Get Microsoft Office for Windows with this lifetime license
  • Kaspersky uncovers fileless malware inside Windows event logs
  • How to find your Windows 11 product key: 3 simple methods
  • How to enable access to god-mode in Microsoft Windows 11

Microsoft allows users to move the taskbar on the standard desktop from the default center position to the optional far left position—but that is it. However, with a very specific binary edit of a very specific key with the Windows 11 Registry File, a user can move the taskbar to the top of their display if they choose.

Move the taskbar to the top of the display in Widows 11

First, a warning and a caveat. This personalization tip requires a binary edit which is much more complicated than our typical Registry File edit. In addition, moving the taskbar to the top of display is not part of Microsoft’s design or specification, so it is possible applications running under this scenario will react oddly and perhaps even crash. Therefore, be certain the taskbar displayed on top of your screen is going to be worth the effort.

Disclaimer: Editing the Windows Registry file is a serious undertaking. A corrupted Windows Registry file could render your computer inoperable, requiring a reinstallation of the Windows operating system and potential loss of data. Back up the Windows Registry file and create a valid restore point before you proceed.

To make our edits in the Windows 11 Registry File, we will type “regedit” into the Windows 11 search tool. From the results, choose the Regedit app and then use the left-hand window to navigate to this key, as shown in Figure A.

Figure A

Click one on the StuckRects3 folder and looking at the right-hand windowpane, double-click the Settings key to reveal the binary contents as shown in Figure B.

Figure B

We are going to make a very careful edit of this binary string to move the taskbar to the top of the display.

With the Edit Binary Value screen open, locate the second row of data, the first value should be 00000008. From there find the value in the fifth column which should be 03. Place the mouse cursor on or just to the right of the 03 and double click. That action should highlight the 03, as shown in Figure C.

Figure C

With the 03 highlighted, press the backspace key once and once only, which will delete the 03 value. Type 01 to replace the missing binary value. The edit should look like Figure D.

Figure D

With the value changed to 01, click the OK button and then close the Registry Editor.

To apply the change, you must restart the Windows Explorer process. Restarting the PC may not be enough to complete the process.

Press the keyboard combination Ctrl+Shift+Esc to open Task Manager. On the Processes tab look for Windows Explorer under the Apps section, as shown in Figure E.

Figure E

Right-click the Windows Explorer item in the list and select Restart from the context menu.

As you can see in Figure F, the Windows 11 taskbar is now displayed at the top of the screen.

Figure F

To change the taskbar back to its normal position at the bottom of the display, edit the same key in the Windows 11 Registry File and replace the 01 with the default 03 and restart Windows Explorer as before.

Addendum: Several readers were curious if it was possible to display the taskbar on the side of a display; apparently, this is preferred for many users of wide displays. Replacing the default 03 in the binary table with 02 will place the taskbar on the left side, replacing 03 with 04 will place it on the right side of the display.

Microsoft Weekly Newsletter

Be your company’s Microsoft insider by reading these Windows and Office tips, tricks, and cheat sheets.

Walter Glenn is a former Editorial Director for How-To Geek and its sister sites. He has more than 30 years of experience in the computer industry and over 20 years as a technical writer and editor. He’s written hundreds of articles for How-To Geek and edited thousands. He’s authored or co-authored over 30 computer-related books in more than a dozen languages for publishers like Microsoft Press, O’Reilly, and Osborne/McGraw-Hill. He’s also written hundreds of white papers, articles, user manuals, and courseware over the years. Read more.

There are all kinds of ways to open a Command Prompt window from File Explorer—and you can even run commands right in the File Explorer address bar—but did you know it’s just as easy to open a File Explorer window from the Command Prompt?

Say you’re in the Command Prompt, working with files and folders, and you want to access them in Explorer. Instead of navigating to them manually, you can get there with one simple command. Go ahead and open up a Command Prompt window by hitting Windows+X and selecting “Command Prompt” from the Power Users menu.

Note: If you see PowerShell instead of Command Prompt on the Power Users menu, that’s a switch that came about with the Creators Update for Windows 10. It’s very easy to switch back to showing the Command Prompt on the Power Users menu if you want, or you can give PowerShell a try. You can do pretty much everything in PowerShell that you can do in Command Prompt, plus a lot of other useful things.

We’re going to be working with the start command, so let’s begin with a simple command to open a File Explorer window for the current folder in Command Prompt. At the prompt, just type the following:

The period is used in the Command Prompt as a shorthand for the current folder, so this will open the current folder in File Explorer.

You can also use a double period to open the parent of the current folder. For example, say that in Command Prompt you were currently looking at a folder named “Reports” that was inside a directory named “Project A.” You could type the following command to open the “Project A” folder in File Explorer without leaving the “Reports” folder in Command Prompt:

And with one command, the “Project A” folder opens up in File Explorer.

You can also build off that double period shorthand be adding a relative path to the end. Let’s continue our example by assuming there was also a folder named “Sales” inside that “Project A” folder. While still in the “Reports” folder, you could type the following command to open the “Sales” folder in File Explorer) without leaving the “Reports” folder in Command Prompt.

Of course, you can also type the full path to open any folder on your PC:

You can also use the command along with any of the built-in Windows environmental variables or the newer shell: operator styles. So, for example, you could type the following command to open the current user’s AppData folder:

Or a command like this to open the Windows startup folder:

So, if you’re typing along at the Command Prompt and want to switch to using File Explorer for some tasks, just remember the humble start command. It’s also great for impressing your less savvy friends. Of course, the start command is also used for running programs and there are a number of additional switches available for that function. If you’re curious about those, just type start /? at the Command Prompt to get a full list of switches and how they’re used.

I see how to launch many other programs from a batch file, but I can’t find a command like open on Mac OS X. Does such a tool exist on Windows? Powershell, or a Windows API call from an executable would also work.

Or, put another way, how can I invoke Windows default “Open” handler for a file from a batch file or powershell script?

5 Answers 5

You can now choose to sort by Trending, which boosts votes that have happened recently, helping to surface more up-to-date answers.

Trending is based off of the highest score sort and falls back to it if no posts are trending.

In Windows you can open Explorer with the following command:

If you want it to open a specific folder, do this for example:

The direct equivalent of OS X’s open is start in cmd .

would launch Notepad (or whatever text editor you’re using),

would launch your browser,

will launch Explorer, etc.

Care has to be taken with arguments in quotes, as start will interpret the first quoted argument as the window title to use, so something like

will not work as intended. Instead prepend an empty quoted argument in that case:

Note that start isn’t a separate program but a shell-builtin. So to invoke this from an external program you have to use something like

The equivalent in PowerShell is either Start-Process or Invoke-Item . The latter is probably better suited for this task.

As for the Windows API, you’re looking for ShellExecute with the open verb.

Bob DuCharme’s weblog, mostly on technology for representing and linking information.

19 October 2007

I use the Windows command line a lot, but some things are easier with the graphical interface, such as deleting or moving a group of files that don’t have some obvious part of their name in common. I’ve know for years that you can start up Windows Explorer from the command line, and you can pass it an argument telling it which directory/folder to open in that window. The following command is a simple way to open up an explorer window for the current directory from the command line:

I recently learned of a Microsoft XP “Power Toy” that performs the opposite trick: when it’s loaded, a folder icon’s right-click menu in explorer includes an “Open Command Window Here” choice that brings you to a prompt with that folder as the current directory.

I was going to write “Does anyone know of an equivalent that runs on Xubuntu?” but a bit of web searching turned up xfe. When you start it from the command line with no parameters, its default behavior is to open a window with icons of the files and subdirectories in your command line’s current directory. Its tool bar includes a little terminal icon that starts up a command line window in the directory for the folder you’re viewing, so you can have it both ways with this one utility.


Here’s a shorter equivalent:

The nice thing about ‘start’ is that, when given a file or URL, will start the system default application to process the parameter:

start mailto:[email protected]
start MyDocument.doc

I’ve been back on a Win32 machine a lot recently, and in the past have found Cygwin must-have. This time even more so – someone suggested the rxvt package, seems an excellent lightweight terminal.

If you wanted to move to regular Ubuntu (with Gnome), then you could type

From the shell to get a window in the current directory. To go the other way, install the (tiny) nautilus-open-terminal package, which adds a menu entry to open a shell in the current directory from a Nautilus window.

Danny and David: Thanks!

Brian: that looks great, I’ll be using that instead of explorer.exe from now on.

For your MyDocument.doc example, though, the “start” isn’t necessary–if a document has an extension that has an app associated with it, merely typing the name of the document will start up the app. This proved very useful about an hour ago when I couldn’t figure out how to tell the Adobe Digital Editions ebook client how to open up a file I had sitting on a disk (they don’t need no stinkin’ “File” menu with an “Open” choice) so I entered the name of the .epub ebook file at the command line and it opened up in the Adobe reader.

On Ubuntu I have a symlink:

lrwxrwxrwx 1 root root 19 2007-08-11 13:11 /usr/local/bin/go -> /usr/bin/gnome-open

I want to click a button on my access form that opens a folder in Windows Explorer.

Is there any way to do this in VBA?

11 Answers 11

You can now choose to sort by Trending, which boosts votes that have happened recently, helping to surface more up-to-date answers.

Trending is based off of the highest score sort and falls back to it if no posts are trending.

You can use the following code to open a file location from vba.

You can use this code for both windows shares and local drives.

VbNormalFocus can be swapper for VbMaximizedFocus if you want a maximized view.

The easiest way is

Which only takes one line!

Thanks to PhilHibbs comment (on VBwhatnow’s answer) I was finally able to find a solution that both reuses existing windows and avoids flashing a CMD-window at the user:

where ‘path’ is the folder you want to open.

(In this example I open the folder where the current workbook is saved.)


  • Avoids opening new explorer instances (only sets focus if window exists).
  • The cmd-window is never visible thanks to vbHide.
  • Relatively simple (does not need to reference win32 libraries).


  • Window maximization (or minimization) is mandatory.


At first I tried using only vbHide. This works nicely. unless there is already such a folder opened, in which case the existing folder window becomes hidden and disappears! You now have a ghost window floating around in memory and any subsequent attempt to open the folder after that will reuse the hidden window – seemingly having no effect.

In other words when the ‘start’-command finds an existing window the specified vbAppWinStyle gets applied to both the CMD-window and the reused explorer window. (So luckily we can use this to un-hide our ghost-window by calling the same command again with a different vbAppWinStyle argument.)

However by specifying the /max or /min flag when calling ‘start’ it prevents the vbAppWinStyle set on the CMD window from being applied recursively. (Or overrides it? I don’t know what the technical details are and I’m curious to know exactly what the chain of events is here.)

Here is some more cool knowledge to go with this:

I had a situation where I needed to be able to find folders based on a bit of criteria in the record and then open the folder(s) that were found. While doing work on finding a solution I created a small database that asks for a search starting folder gives a place for 4 pieces of criteria and then allows the user to do criteria matching that opens the 4 (or more) possible folders that match the entered criteria.

Here is the whole code on the form:

The form has a subform based on the table, the form has 4 text boxes for the criteria, 2 buttons leading to the click procedures and 1 other text box to store the string for the start folder. There are 2 text boxes that are used to show the number of folders listed and the number processed when searching them for the criteria.

If I had the Rep I would post a picture. :/

I have some other things I wanted to add to this code but haven’t had the chance yet. I want to have a way to store the ones that worked in another table or get the user to mark them as good to store.

I can not claim full credit for all the code, I cobbled some of it together from stuff I found all around, even in other posts on stackoverflow.

I really like the idea of posting questions here and then answering them yourself because as the linked article says, it makes it easy to find the answer for later reference.

When I finish the other parts I want to add I will post the code for that too. 🙂

A neat feature that’s available with the command prompt is the ability to use drag and drop from Windows Explorer to copy the path. It doesn’t change the directory, but you can use it to make things a lot easier.

This feature is not available when you run the command prompt using Run As Administrator.

Using Drag and Drop with the Command Prompt

  1. If a command prompt is not already open, launch a command prompt
  2. Launch Windows Explorer and browse to the Libraries\Documents\My Documents folder
  3. Position Windows Explorer and the Command Prompt window side by side
  4. Click My Documents in Windows Explorer, drag it to the Command Prompt window, and release it You’ll notice that the path is now displayed in the window Your display will be similar to the following graphic.
  5. In the figure, the user name is Mike, so the default path of Mike Libraries starts as C:\Users\Mike and the actual path to the Libraries\Documents\My Documents folder is C:\Users\Mike\Documents When the My Documents folder is dragged and dropped into the Command Prompt window, the path is typed out However, you’re not finished yet.
  6. Use the left arrow (or the Home key) to position your cursor to the left of all the text Type CD and a space to modify the command, and press Enter Your path will be changed to the equivalent of the My Documents folder.

TipYou can easily change the path using Windows Explorer, but you can also launch the command prompt to any folder’s location from Windows Explorer Press the Shift key, right-click the folder, and select Open Command Window Here The command prompt will be launched with the directory set at the same folder as Windows Explorer.

Windows Explorer can basically be set to either open each new folder in a new window or all folders in the same. Windows users who want to mix the two modes have the problem that it appears to be more difficulty than though.

Most launch a new Windows Explorer window and navigate to the folder they want to view in the new window. Some launch the new instance from the taskbar, some use the keyboard shortcut Windows-E to do so.

Both methods have the problem that the user needs to manually navigate to the folder first before work can be continued.

There are actually two ways to open a new Windows Explorer window directly in the program, with the selected folder as the starting folder.

A right-click on any folder in Windows Explorer displays a context menu, this is true for the standard display but also the sidebar if it is enabled and available in the Windows operating system. Among the items in the context menu is the option to spawn the selected folder in a new window.

open in new window

That’s however not the fastest option to spawn a new Windows Explorer window. Holding down CTRL while double-clicking a folder will open the contents of that folder in a new Windows Explorer window.

This is the fastest way to open a new window in Windows Explorer from another Windows Explorer window, providing that the default setting has been set to display all folders in the same Explorer instance.

Got more handy Windows Explorer tips to share? Let us know in the comments.

I am new to Ubuntu, and was wondering whether it is posible to open a terminal with a path matching your current location in the file manager? In Windows it was very easy, but how do you do it in Linux?

13 Answers 13

Run sudo apt-get install nautilus-open-terminal in a terminal, followed by nautilus -q to quit all open nautilus windows. When nautilus is next opened, a line saying open in terminal should appear in the right click menu.

Please note that the package nautilus-open-terminal is in the universe repositories.

With Dolphin , KDE’s file manager, you have two options:

Open a terminal as a panel in the same window. Use the keyboard shortcut F4 or the menu: ControlPanelsTerminal.

The working directory is synchronized between the two panels; changing directories in either of the two panels will also change it in the other. Sweet!

In this screenshot you even see the sweetness of having this as a toolbar item in the top.

Open a terminal in a new window. Use Shift + F4 to do that. It will not have the feature to have the working directory synchronized, but it just opens a new window with the current working directory set.

The same applies to other apps in KDE Plasma, like the Kate text editor (enable it in Kate’s settings, it’s a built-in plug-in). Opening a terminal with a single keyboard shortcut from your text editor with the context of the file, is simply brilliant.

Update , April 11

Create a simple script with the following contents

Bind that script to a shortcut , for instance Ctrl + Alt + i , or whatever you like.

Now, when you are in some directory in nautilus, press Ctrl + L to open address bar. Copy the address of your current directory with Ctrl + X .

Lauch the shortcut you just created and paste the address with Ctrl + V in to the dialog. Terminal should pop-up with the directory that you told the dialog to open.

IMHO, this is as “native” as it gets and doesn’t require additional installation. Sure, it is not a right click type of thing, but it works and can be implemented quickly. Will work for other file managers that don’t support this option,too

Original Post

Technically nautilus, the default file manager, doesnt have open terminal here option, but there is a plug in for that in the repositories. You might be more interested in other file managers that support this option out of the box

As a workaround you could try the following:

Ctrl + L willopen the text filed for entering address, with the current working directory highlighted. Cut that out with Ctrl X , and paste into terminal with Ctrl Shift V or right click. Alternative , use run dialog to launch gnome-terminal –working-directory= and paste whatever you copied after = sign.

Drag and drop: Drag the button/tab (not sure how it’s called) into terminal, add cd in front

Another way: Open the file manager and terminal. Drag and drop the folder you want to access into terminal, and add cd to the path.

For instance, if I want to access bin directory in my /home/serg/ directory, i would drag that directory to terminal and it would appear as ‘/home/serg/bin’ . Next, add cd , so that the whole line is cd ‘/home/serg/bin’ .

Tip / Trick

The Command Prompt has been around in Windows for a long time. It’s worth getting to know many of the different ways you can open it because it is a useful tool that can help make your time with Windows a lot easier. Most techies know quite a few commands off by heart, but you can also cheat at any time and just look up what the codes are that you need.

The point of the Command Prompt is to offer a way to do things that you wouldn’t be able to do from a graphical interface. It also provides a way to be able to do things quicker than you would be able to from a Windows graphical interface.

You can accomplish a lot from the command line. It isn’t as powerful as the Windows PowerShell, but it’s still a useful place that has been around in Windows almost forever.

How to Open Command Prompt from Win+X Quick Link Menu

Microsoft changed what was available from the Win+X menu in Windows 10 build 14971 to now show the PowerShell links there instead. However, the option to open the command line didn’t disappear altogether. You can still use the Settings app to swap the PowerShell for the Command Prompt if you prefer.

Once you have made the swap, press the Windows logo + X keys on your keyboard to bring up the menu and then click on either of the two Command Prompt entries to open a Command Prompt window—the one with “Admin” next to it being the one you want if you need to use the command line with administrative permissions to execute your tasks. (It’s also worth mentioning that it’s possible to put up the same menu by right-clicking the mouse on the Start button.)

How to Open Command Prompt from Task Manager

Open the Task Manager and then click on File > Run new task.

Type “cmd.exe” to open a Command Prompt window. (You also have the option of creating the Command Prompt window with administrative permissions by putting a checkmark in the checkbox below where you are typing the CMD executable.)

How to Open Command Prompt in Search

Type “CMD” into the search field that’s available from the taskbar and then click on the “Command Prompt” desktop application that appears under the Best match section to open a Command Prompt window.

How to Open Command Prompt from All apps in Start Menu

Click on the “Start” button and then scroll down the All Apps menu and click the “Windows System” folder entry to reveal the Command Prompt. Click where it says the “Command Prompt” to open a new Command Prompt window.

How to Open Command Prompt from File Explorer

Head to the Start menu > File Explorer and then type C:\Windows\System32 as the folder address in the available bar at the top of the window and then scroll down until you can see the cmd entry. Click on “cmd” with the black icon next to it to open a new Command Prompt window.

How to Open Command Prompt from Run

Open a Run dialog box by pressing the Windows logo + R keys on your keyboard and then type “CMD” and click or tap on the “OK” button to open a new Command Prompt window.

The Command Prompt supports many quick keyboard shortcuts that can all be used no matter what way you open up the Command Prompt window. You should also have no problems executing those commands from a window that you opened using the guide above from most versions of Windows to date, and not just Windows 10.

An * .exe or program under Windows (11, 10, 8.1, 7) can be started via the command line via the command prompt!

Regardless of whether you want to start an APP or program via a program argument / command line via the command prompt and regardless of whether it is a Windows desktop, tablet, Surface Pro / Go, or even a server operating system, the solution is and the procedure is the same.

cmd / k “c:\Windows\explorer.exe”

Or use start to have more options!

start explorer /low /max

Here is an overview of the STAR options!

Microsoft Windows [Version 10.0.22000.71] (c) Microsoft Corporation. All rights reserved. C:\Users\Nenad>start /? Starts a separate window to run a specified program or command.

START [“title”] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/NODE ] [/AFFINITY ] [/WAIT] [/B]
[command/program] [parameters]

“title” Title to display in window title bar.
path Starting directory.
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application.

I The new environment will be the original environment passed
to the cmd.exe and not the current environment.

MIN Start window minimized.

MAX Start window maximized.

SEPARATE Start 16-bit Windows program in separate memory space.

SHARED Start 16-bit Windows program in shared memory space.

LOW Start application in the IDLE priority class.

NORMAL Start application in the NORMAL priority class.

HIGH Start application in the HIGH priority class.

REALTIME Start application in the REALTIME priority class.

ABOVENORMAL Start application in the ABOVENORMAL priority class.

BELOWNORMAL Start application in the BELOWNORMAL priority class.

NODE Specifies the preferred Non-Uniform Memory Architecture (NUMA)
node as a decimal integer.

AFFINITY Specifies the processor affinity mask as a hexadecimal number.
The process is restricted to running on these processors.

The affinity mask is interpreted differently when /AFFINITY and
/NODE are combined. Specify the affinity mask as if the NUMA
node’s processor mask is right shifted to begin at bit zero.
The process is restricted to running on those processors in
common between the specified affinity mask and the NUMA node.
If no processors are in common, the process is restricted to
running on the specified NUMA node.

WAIT Start application and wait for it to terminate.
If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to cmd.exe.
This means that the window will remain after the command
has been run.

If it is not an internal cmd command or batch file then
it is a program and will run as either a windowed application
or a console application.

parameters These are the parameters passed to the command/program.

NOTE: The SEPARATE and SHARED options are not supported on 64-bit platforms.

Specifying /NODE allows processes to be created in a way that leverages memory
locality on NUMA systems. For example, two processes that communicate with
each other heavily through shared memory can be created to share the same
preferred NUMA node in order to minimize memory latencies. They allocate
memory from the same NUMA node when possible, and they are free to run on
processors outside the specified node.

start /NODE 1 application1.exe
start /NODE 1 application2.exe

These two processes can be further constrained to run on specific processors
within the same NUMA node. In the following example, application1 runs on the
low-order two processors of the node, while application2 runs on the next two
processors of the node. This example assumes the specified node has at least
four logical processors. Note that the node number can be changed to any valid
node number for that computer without having to change the affinity mask.

start /NODE 1 /AFFINITY 0x3 application1.exe
start /NODE 1 /AFFINITY 0xc application2.exe

If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:

non-executable files may be invoked through their file association just
by typing the name of the file as a command. (e.g. WORD.DOC would
launch the application associated with the .DOC file extension).
See the ASSOC and FTYPE commands for how to create these
associations from within a command script.

When executing an application that is a 32-bit GUI application, CMD.EXE
does not wait for the application to terminate before returning to
the command prompt. This new behavior does NOT occur if executing
within a command script.

When executing a command line whose first token is the string “CMD ”
without an extension or path qualifier, then “CMD” is replaced with
the value of the COMSPEC variable. This prevents picking up CMD.EXE
from the current directory.

When executing a command line whose first token does NOT contain an
extension, then CMD.EXE uses the value of the PATHEXT
environment variable to determine which extensions to look for
and in what order. The default value for the PATHEXT variable

Notice the syntax is the same as the PATH variable, with
semicolons separating the different elements.

When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name. If it does, the
START command launches the Explorer on that path. If done from the
command line, it is the equivalent to doing a CD /D to that path.

You can always use the solution, regardless of whether it is in the new MS Windows OS or on one of the following operating systems: — OS_Windows6 — it has been tested on all and successfully verified .


zomgrolf commented Aug 2, 2021

Windows Terminal version (or Windows build number)

1.9.1942.0 (Windows version: 10.0.19043.1110)

Other Software

Steps to reproduce

  1. Create an empty directory, e.g. c:\temp\rmdir_test
  2. Open explorer.exe and navigate to the newly created directory.
  3. In the address bar, type wt -d . to launch a new instance of Windows Terminal with Command Prompt as the default profile.
  4. Close the explorer window.
  5. In the command prompt type cd .. to go the the directory above ( c:\temp ).
  6. Type rmdir rmdir_test to attempt to delete the empty rmdir_test directory

Expected Behavior

I was expecting to be able to delete the rmdir_test directory without having to close the terminal window.
If I repeat the above steps using conhost instead of Windows Terminal (i.e. typing cmd.exe in the address bar instead of wt -d . ), I can delete that directory just fine, with the command prompt still open.

Actual Behavior

I get the following error: The process cannot access the file because it is being used by another process.

If I look for the handle in Resource Monitor, I get this:

It seems that the Terminal retains that file handle for as long as the process is alive, even if I navigate away from the starting directory.

Seems to be similar to #9664, which was marked as resolved and closed, although I don’t really see any solutions in there that would be applicable in my case.

The text was updated successfully, but these errors were encountered:

vefatica commented Aug 2, 2021

It’s still the current working directory of windowsterminal.exe and openconsole.exe.

zomgrolf commented Aug 2, 2021

vefatica commented Aug 2, 2021

A process always has an open handle to its current working directory.

zomgrolf commented Aug 2, 2021

And the current working directory stays the same forever because.

eryksun commented Aug 2, 2021

A process keeps its working directory open without shared delete access, which prevents the directory from being deleted or renamed until the directory is closed (e.g. the working directory changes or the process terminates). Notably, the base API uses the handle for the working directory to open relative file paths (see NTAPI OBJECT_ATTRIBUTES RootDirectory ), which is similar to openat() in POSIX systems.

And the current working directory stays the same forever because.

Because “WindowsTerminal.exe” and “OpenConsole.exe” never change their inherited working directory? I guess they could change it to the system directory.

vefatica commented Aug 2, 2021

I think there are situations in which windowsterminal.exe changes its CWD . using “Open in Windows Terminal” with a re-used instance. IIRC, folks wanted new shells opened in “.” to follow the “open in” mechanism around. (yes/no?)

zadjii-msft commented Aug 2, 2021

That’s correct. When you’ve got the windowing behavior set to re-use an existing window (the second two options here:

), or when you do a wt -w N — whatever.exe , we’ll have the wt opening the commandline switch to the CWD of the source of the commandline, spawn that connection, then switch back. This is to make sure profiles that have their startingDirectory set to something like . work correctly.

zomgrolf commented Aug 2, 2021

So how do I force Windows Terminal to change the current working directory when I change the directory in the command prompt?

vefatica commented Aug 2, 2021

So how do I force Windows Terminal to change the current working directory when I change the directory in the command prompt?

The short answer is you can’t. Why would you want to?

zomgrolf commented Aug 2, 2021

Consider the following scenario:

  1. A developer launches the terminal from a directory that contains some build artifacts (e.g. CMake configuration cache or maybe some other files generated as a part of the build process, or perhaps not even build artifacts, it doesn’t really matter). She or he does some work on the command line in that directory, then switches away to another directory on the filesystem.
  2. Over the course of the next hour(s), said developer launches a number of other terminal windows (possibly with tabs), working on some other (maybe related, maybe not) things in other areas of the filesystem.
  3. At some point (s)he decides to build the first project. Or maybe hands over the machine to another developer who needs to do a full rebuild. In this case, certain builds are done from scratch and involve wiping clean the entire build area and resyncing the source code and all dependencies. And so that other developer triggers a full rebuild — except now the part that does the cleanup mysteriously fails, although it used to work fine. It’s not immediately obvious what is the cause and why that directory could not be deleted — it doesn’t contain any executables/dlls that could be locked by a running process, none of the open command prompts have it set as their current directory.

That’s because someone else started the terminal from that directory a few hours ago.

At this point your option is to look for the handle, then try to match the PID of the process that owns it with the right instance of the terminal and close it, otherwise you won’t be able run the automated build process. Not the best user experience.

And if that first terminal was actually used to start some long running process (e.g. a regression suite for another build configuration, 8+ hours total and you’re on hour 4), then you’re out of luck.

Mind you, all of this works with the old conhost just fine — there are no issues with deleting the starting directory, so from our point of view, this is effectively a regression.

Not sure how it fits with the plans for making Windows Terminal the default terminal in the future.

Dewwa Socc July 27, 2020 General Comments Off on Making Windows Explorer work as you wish!

Making Windows Explorer work as you wish!

If you have been accessing files on your Microsoft Windows 95, Windows 98, or Windows NT 4.0 based computer, you have no doubt done so using Windows Explorer. When using Windows Explorer, it typically opens to the default view displaying the contents of “C” drive. We are frequently ask how this can be changed to make it start with a different drive, or even start with no drives open at all. There are no special registry hacks, its all a matter of knowing which command line switches to use in the Windows Explorer short cut that is part of the Start Menu. The following will walk you through the common switches and why some work well and others not very well at all.

Windows Explorer’s Command Line Switches

The following chart shows the command line switches for Windows Explorer.

Windows Explorer Switches

The switches shown above control the type of display Explorer will use, including the initial folder, selection and scope of the Explorer window opened. You can display the contents of a drive or folder in two different ways. If you right-click a folder and choose Open, you get a single-pane view, where each file or folder is represented by a large icon and a title. Explorer “recycles” windows of this type by default, which means that if the desired folder is present in an existing open view window, Explorer will activate that window rather than opening a new one.

If you right-click a folder and choose Explore, you get a two-pane view called the explore view, which is represented by a folder tree that appears in the left-hand pane, and the right-hand pane lists details about each file or folder, including the name, size, type, and last-modified date. If neither of the two switches are present, [/n] or [/e], Explorer uses the open view and recycles existing windows. The [/n] switch disables window recycling and forces a new open view window. The [/e] switch forces the explore view, whereupon Explorer does not recycle existing windows. If both the [/n] and [/e] switches are present, [/e] is ignored.

The [subobject] and [/select,subobject] switches control the initial Explorer display. When a folder name is added to the Explorer.exe command line to open that folder, you’re using the [subobject] switch. If you precede the full pathname of a file or folder with [/select], Explorer launches and highlights the specified file or folder with its parent opened. The command [explorer /e,/select,c:\windows\system] would cause explorer to open the c:\windows folder and highlight the system folder within it.

The [/root,object] switch is powerful not often used. The root folder is at the top of Explorer’s folder tree and has no parent as it shows the Desktop, by default. By using the [/root] switch, you can specify any drive or folder as the root for the Explorer display. As an example, you could create an Explorer window that displays only drive “C:”, with no direct access to virtual folders like Printers, Control Panel and the like.

This will give you a better understanding: Open an MS-DOS prompt, navigate to any folder and enter the command explorer /e,. (explorer, space, slash, e, comma, period.) Let’s understand what these entries mean.

  • The “explorer” entry is the Windows Explorer program.
  • The “space” let’s allows the program to distinguish that a command is coming.
  • The “slash” precedes the actual command switch.
  • The “e” or “n” are the actual switches. (see the chart above)
  • The “comma” is a break between switches.
  • The “period” ends the command line and represents the current folder so that you get a two-pane Explorer window showing that folder.

You can experiment with these switches right at the “command prompt” or “MS-DOS prompt”. When you find a combination you like, you can create a shortcut using that exact command, or you can insert it into an existing shortcut. Here are some switch combinations you may want to try:

This opens a two-pane Explorer view with none of the drives expanded. This is handy if you have multiple drives and use them all frequently.

This opens a two-pane Explorer window that initially displays the contents of drive D:.

This switch combination opens a two-pane window that initially displays the contents of the data folder on drive D:, and from which the user cannot navigate anywhere other than in or below that folder.

This opens a two-pane window that initially displays the contents of the data folder on drive D:, and from which the user cannot navigate anywhere other than drive D:.

Creating a new shortcut:

To create a new shortcut using a particular command line, right-click the desktop and choose New, Shortcut from the popup menu. Enter the entire command line in the Create Shortcut dialog. If you have just tried the shortcut at an MS-DOS prompt, you can copy it from the prompt and paste it into the dialog. Click Next and give the shortcut a name such as Explorer rooted on D. Now click Finish. You will find the new shortcut on your desktop.

To move it to your Start menu, simply drag it and drop it onto the Start button. This puts the menu item in the main body of the Start menu, above the Programs menu. To move the item into the Programs menu, right-click the Start button and choose Explore. Windows Explorer will display the shortcuts and folders that define the Start menu; just drag the shortcut into the Programs folder or into one of its subfolders.

Changing a Desktop’s Shortcut Command Line:

To change a desktop shortcut’s command line, right-click the shortcut and choose Properties. The Target field on the Shortcut tab of the dialog is the command line you want. Now enter your new command line. If the shortcut you want to change is in the Start menu, right-click on the Start button and choose Explore from the pop-up menu. Now navigate to the menu folder that holds the shortcut you want, and modify it as described above.

When the switches don’t work as they should:

On some Windows configurations, the switch [/select,subobject] seems to fail. The subobject’s parent folder opens in the left pane and highlighted in the folder tree, but nothing is visibly highlighted in the list of files and folders. If you press the Tab key to move the focus to the detail list, you’ll see that the subobject is indeed selected.

The Microsoft Knowledge Base documents several instances where the various switches do not work.

Article Q208114, “Windows Explorer /N Switch Does Not Open a New Window“, the command Explorer [/n] fails to disable window recycling under Windows 98 and Windows 98 SE. Microsoft recommends using the [/e] switch instead.

Article Q237494, “The Explorer Command Does Not Select the Correct File“, states that in Windows 98 SE, the [/select] switch without [/n] or [/e] may not select the correct file if the folder that contains it is already open. Microsoft does not offer a workaround for this problem. For some unknown reason these vagaries do not effect all Windows 9x based systems.

The grep command in Linux is widely used for parsing files and searching for useful data in the outputs of different commands.

The findstr command is a Windows grep equivalent in a Windows command-line prompt (CMD).

In a Windows PowerShell the alternative for grep is the Select-String command.

Below you will find some examples of how to “grep” in Windows using these alternatives.

Cool Tip: Windows touch command equivalent in CMD and PowerShell! Read more →

Grep Command in Windows

Grep the output of a netstat command for a specific port:

If a command in PowerShell returns some objects, before parsing, they should be converted to strings using the Out-String -Stream command:

Grep a file for a pattern that matches a regular expression (case insensitive):

Options used by the findstr command in the example above:

Display help for the Windows grep command equivalents:

Cool Tip: Windows cat command equivalent in CMD and PowerShell! Read more →

16 Replies to “Windows: `Grep` Equivalent – CMD & PowerShell”

Hi. I tried to type in the cmd prompt
` C:\> netstat -na | findstr “2020”` and enter, and it doesn’t work. I want to search in directories of word document some strings. It seems that I missed something in your explanations

What you want is this section of the article:
# Windows CMD
C:\> findstr /i “^SEARCH.*STRING$” file.txt
In the example above you can change “^SEARCH.*STRING$” to “2020”. i.e.
C:\> findstr /i “2020” *.txt
The above command will search for “2020” in all txt files in your current directory.

Great write-up. I found exactly what I needed.
One correction, though, is in invoking findstr’s help, which follows the customary form of other Windows commands: findstr /?

PS C:\Users\Administrator> auditpol.exe /get /category:* | findstr “Directory Service Replication”
Certification Services No Auditing
Directory Service Changes No Auditing
Directory Service Replication No Auditing
Detailed Directory Service Replication No Auditing
Directory Service Access No Auditing
Kerberos Service Ticket Operations No Auditing
Kerberos Authentication Service No Auditing

i want exact match plz help me its urgent

use find instead of findstr (findstr will return all matches Directory or Service or Replication, find will return a match of the entire string (case sensitive). Use find -i to ignore case.

i want the one output that one exact match word to word

auditpol.exe /get /category:* | findstr /C:”Directory Service Replication”

Would you know why the Select-String command in PowerShell returns just the pattern match vs. findstr returning the entire line like grep would?
For example:
If I use Set-Alias -NAME grep -Value Select-String
‘Get-Alias |Select-String grep’ will return:
‘Get-Alias |findstr grep’ will return:
Alias grep -> Select-String

Is there a way to get the same output of Select-String sofor the sake of using PowerShell commands only?

It is the behavior of the get-alias command that is giving the trouble.
Turn the output into strings first:
‘Get-Alias | Out-String -stream | Select-String grep’

Thanks a lot. useful for me.

Nice information and may help me solve a mystery. thanks

I’m trying to created a batch file for win 10 to find a particular process that likes to “hang” all the time. The thing is it’s pid changes every use. I’m an ex introductory level to intermediate programmer, and “hang” a lot of processes as I develop corny software in my old age. I need to use something like tasklist to list all NON RESPONSIVE processes, find the process or PID I need to kill and send that info to taskkill to get the job done. If anyone reads this and can help me out with a decent batch file, it would be very appreciated. I’ve read a lot of articles alreay, but can’t seem to get it to work. Thanks in advance to the best person I could honestly say at this point is the best person in the world 🙂

I have a large TXT file with tens of thousands of lines.
I want to find all the 500 or so lines that contain a particular string (for example “popup”) and extract those just lines into another output file for further processing. The string is unique to the lines I want extracted, and occurs just once in each such line.
I have not programmed in years (fortran, BASIC, Excel macros), but I am willing to learn something modern. I am on a Win10 notebook and looking for advice: What would be the easiest & quickest (Python, Perl, Powershell, … . ) that would allow me to do the above?

The powershell Select-String command will do that just fine with the right regex, as will most other shell languages. In powershell you can run this command:

Select-string ‘^.*YOURSTRING.*’ c:\PATH\TO\INPUTFILE.TXT | % <$_.Matches.Value>> c:\PATH\TO\OUTPUTFILE.TXT

Quick breakdown of that command:
* The regex ^.*YOURSTRING.* selects the entirety of every line that contains YOURSTRING
* % <$_.Matches.Value>selects only the regex lines; without it your output file will have the file name and line number on each line
* > writes the output to a file

for i in `ls lig*pdbqt`;do echo $i;grep ATOM $i | cut -c-66 > `basename
$i .pdbqt`.pdb;done
this is a linux command which i want to use on my windows cmd. Can someone convert it for me please? Thank you

There is no reason why PowerShell and/or Command couldn’t implement “grep” and call it grep. Grep has been around since the start, thanks Ken Thompson, it’s open source and everyone knows it.

Microsoft, don’t try to reinvent the wheel, it’s been around for a long time and it works.

A Command Prompt allows you to run programs, manipulate Windows settings, and access files by typing in commands that you wish to execute. To start a Command Prompt you simply need to type cmd.exe in the search field in the Start menu or click on Start, then Accessories, and then click on the Command Prompt icon. A window will appear, called the Command Prompt, that will open in your user profile folder and wait for you to issue commands. An example of this Command Prompt can be seen below:

Default Command Prompt Window

The problem with the standard Command Prompt is that any commands you run in it operate as if you do not have Administrative privileges. So you won’t be able to run any commands or access any files that require these privileges.

It is for this reason, that we need to be able to open what is called an Elevated Command Prompt, which is a Command Prompt that allows you to access files and programs as an Administrator of the machine. There are three methods that can be used to open an Elevated Command Prompt and I have outlined them both below.

Method 1: Run As Administrator from shortcut

The first method is to launch the Command Prompt as an Administrator. This can be achieved by clicking on the Start menu, then selecting All Programs, and then Accessories. You will now see a shortcut labeled Command Prompt. Right-click on it and select Run as administrator as shown below.

Run as administrator

When you select Run as administrator a User Account Control prompt will appear asking if you would like to allow the Command Prompt to be able to make changes on your computer.

User Account Control Prompt

Click on the Yes button and you will now be at the Elevated Command Prompt as shown below.

Elevated Command Prompt

Please note that the Elevated Command Prompt starts in the Windows System32, for example C:\Windows\System32\, folder rather than the User Profile. In this Elevated Command Prompt you can now launch programs or access files that require Administrative privileges.

Method 2: Use Ctrl+Shift+Enter to launch Cmd.exe

It is also possible to launch cmd.exe from the Start Menu search field by using the Ctrl+Shift+Enter keyboard combination. To use this method, click on the Start menu and in the search field enter cmd as shown in the image below.

cmd.exe in the Start Menu search field

Once you type cmd, press the Ctrl+Shift+Enter keyboard combination and cmd.exe will be launched as if you selected Run as Administrator. You will then see a User Account Control prompt asking if you would like to allow the Command Prompt to be able to make changes on your computer. Click on the Yes button and you will now be at the Elevated Command Prompt.

Method 3: Create an Elevated Command Prompt Shortcut

If you find that you use the Elevated Command Prompt often and would like an easier way to launch it, you can make a short cut to it on your desktop or pinned to your Taskbar. To do this you can click on the Start menu, then selecting All Programs, and then Accessories. You will now see a shortcut labeled Command Prompt. Right-click on it and either drag it to your desktop and copy it there, select Pin to Start Menu, or select Pin to Taskbar (Windows 7 only). Once the Command Prompt shortcut is where you want it, right-click on it and select Properties.

In the properties screen, make sure you are on the Shortcut tab and click on the Advanced button. You will now be at a screen similar to the one below.

As shortcut’s advanced properties screen

At this screen put a checkmark in the box labeled Run as administrator, as shown above, and then click the OK button. Then click OK one more time to exit the shortcut’s properties. Now whenever you double-click on this shortcut it will automatically run the Command Prompt with elevated privileges.

For more information on the Command Prompt and its available commands you can view our Introduction to the Windows Command Prompt tutorial. As always, if you have any questions regarding this procedure please ask us in our Windows 7 forum.

Users who read this also read:

How to enable and disable the Windows Administrator account

The built-in Administrator account is disabled by default in Windows 8, Windows 7, and Windows Vista. It is disabled to enhance security as this is a common account targeted by hacking scripts and hackers when they try and access your computer without your permissions. In my opinion, you should leave the Administrator account disabled, but as there have been many requests for this information, I .

How to rename the built-in Administrator account in Windows

The built-in Administrator account is one of the most targeted account names by malicious programs and hackers that are attempting to access your computer without your permission. It is therefore a wise security precaution to rename the Administrator account to another less common name so that it can no longer be targeted. By default, the Administrator account in Windows Vista, Windows 7, and .

Introduction to the Windows Command Prompt

Before Windows was created, the most common operating system that ran on IBM PC compatibles was DOS. DOS stands for Disk Operating System and was what you would use if you had started your computer much like you do today with Windows. The difference was that DOS was not a graphical operating system but rather purely textual. That meant in order to run programs or manipulate the operating system .

How to enable GodMode in Windows

Windows 8, Windows 7, Server 2008, and flavors of Windows Vista provide an unpublished ability to create a control panel called GodMode that alllows you to have easy access to almost all administrative tasks that you would like to use in Windows. This new window is called GodMode because it puts all aspects of the management of Windows at your fingertips in one location. This allows you to quickly .

How to open an Elevated Command Prompt in Windows 8

A Windows Command Prompt is a screen where you type in commands that you would like to execute. The command prompt is very useful if you want to use batch files, basic scripting, or to perform various administrative tasks. The normal command prompt has one shortcoming and that is that you cannot directly launch programs that require administrative privileges in order to work properly. This is .