Hot answers tagged

39 votes
Accepted

Cannot `cd` to E: drive using Windows CMD command line

Using cd/chdir you cannot change the current working directory (CWD) to one on a different drive unless first switching drives (2 steps) or including the /d switch as part of your command (1 step). cd ...
  • 1,502
22 votes
Accepted

How do I pass the password to a net use command which contains % at the end?

There are a few solutions to your problem Use a variable for the password set "password=b91A*9AIvPr%" net use \\192.168.40.40 /user:192.168.40.40\Administrator %password% Use a ...
  • 336
7 votes
Accepted

Echo to clipboard with special characters

What is wrong? the clipboard is empty using the following: echo 28376^>1847|clip The reason it doesn't work as expected is: When piping or redirecting text, applying an escape character gets a ...
  • 149k
7 votes
Accepted

How can I get the pid by its executable path in Windows?

How can I get the process ID of a program from its absolute file path? Something like the following: wmic process get ProcessID,ExecutablePath | findstr /c:"C:\apps\Program Files\Notepad++\...
  • 149k
6 votes
Accepted

How to `cmd /V:ON` in line with another command to run sequentially

If you really want / have to do it as a one-liner directly on the command prompt: @>nul set filenum=1&@for %f in (*.txt) do @(cmd /v:on /c ECHO ren "%~nxf" "!fileNum!%~xf"&...
  • 1,518
5 votes

grep is not recognized as an internal or external in windows

Use findstr instead grep, because cmd doesn't cover grep syntax as it works on Linux.
  • 51
5 votes
Accepted

How can I determine the file system of a given drive letter from a Windows 10 NON-ADMIN cmd.exe?

wmic doesn't require administrator elevation. To get all disks : wmic volume get DriveLetter,FileSystem To list one disk (D) : wmic volume where DriveLetter='D:' get FileSystem
  • 431k
4 votes

Unable to use ANSI Escape Sequences in Windows 10

Those aren't complete escape sequences; they're missing the actual ESC character (byte 0x1B) in front of the [7m. In other languages you see it written down as \e or \033 or \x1B, but Cmd has no ...
  • 401k
4 votes

What's the purpose of 'run as administrator' when using cmd or powershell?

Why should I run as administrator every time when I use cmd or powershell? You really should not. Why does one need Admin rights at all? To change certain system settings and to access/edit certain ...
  • 57.1k
3 votes
Accepted

7-zip windows command to extract .rar from a networkshare recursively but keep files in the dir with the .rar file

You could do the following for /f %i in ('dir /b /s *.rar') do pushd "%~dpi" & 7z x "%i" & popd With the pushd you change the directory, %~dpi extracts the directory from ...
3 votes

Why does wmic lie about its output for "BytesReceivedPersec" and "BytesSentPersec"?

Class Win32_PerfRawData has "Raw" data, it needs to be processed before it shows the actual stats. You must instead use the class Win32_PerfFormattedData which has "Formatted" data....
3 votes

in batch For loop , echo %%i:~0,5% doesn't work

Why doesn't this command work? for /F %%i in ('dir c:\logs /A:-D/B') do @echo %%i:~0,5% You need to use a temporary variable as you cannot extract text from a loop variable. You need to use delayed ...
  • 149k
3 votes

How to `cmd /V:ON` in line with another command to run sequentially

I cant do variable expansion without doing cmd /V:ON on the command line first. Correct. However the following should work: cmd /V:ON /c "set/a fileNum = 1 & for %f in (*.txt) do ( rename %~...
  • 149k
3 votes

Unable to use ANSI Escape Sequences in Windows 10

You have to use chr(27) (a.k.a "ESC") to make the ansi sequence complete. You can obtain it with: for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for ...
  • 1,518
3 votes

How to navigate to desktop when desktop is on seperate drive

The following solution work if you are using the Windows menu to open CMD : Use Windows key to open Windows menu Search "cmd" Right click on the command prompt Open the file location Right ...
  • 1,037
3 votes
Accepted

What is the path to the `dir` program on Windows from `cmd.exe`?

What is the path to the dir program? It doesn't have one. dir is one of several commands that are internal to the cmd shell. The full list can be found at Internal commands - Windows CMD - SS64.com ...
  • 149k
3 votes

How can I determine the file system of a given drive letter from a Windows 10 NON-ADMIN cmd.exe?

Here is how to achieve the same action in WMI using PowerShell since wmic is being deprecated. To get just D:, use the following command (Get-WmiObject). Get-WmiObject -Class Win32_Volume | Where-...
3 votes
Accepted

How to pull Email and password only from a text file in CMD?

Get each line (%%a) and split it into "words" (%%b). Test each "word" if it matches the desired format (containing @ and :). If it matches, echo it. Finally, redirect the output to ...
  • 1,518
2 votes
Accepted

Refining a simple delete-item one-liner

First of all, the Path and LiteralPath Property of Remove-Item accept wildcards, so your current one liner would already work without Get-ChildItem Remove-Item \\HQDEVAPP004\C$\LoneStar\...
  • 201
2 votes
Accepted

How to delete folder named "..." on Windows

If it is not empty, use rmdir /s /q to delete its contents recursively. rd/s/q \\?\C:\etc\etc\... Suffixing the path with \ would also bypass the stripping of trailing .'s. rd/s/q ...\
  • 401k
2 votes
Accepted

CMD command in Dockerfile doesn't execute when I run docker build

It's not supposed to be run. CMD defines the default command to run when you execute the container, not when you build it. You'll see the value set when you inspect the image. Note there is only one ...
  • 1,885
2 votes

Kill specific started process in Windows

If you have only one such process, you may kill the executable: taskkill /im python.exe If the process is stubborn and doesn't terminate, add the /f parameter to forcefully terminate the process. For ...
  • 431k
2 votes
Accepted

Windows 11 command prompt printing characters instead of coloured text

Those ] things are part of the ANSI sequence for formatting. The terminal in VS Code supports ANSI sequences so obviously you'll see color properly. The one you're seeing on the screenshot is conhost....
  • 24.7k
2 votes

Need Remote computer to grab local files

Instead of Entering PSSession you can create it and store it in variable. $StagingSession = New-PSSession -ComputerName StagingServer -Credential AdminUser Then you can use Copy-Item with argument -...
2 votes
Accepted

On Windows 10/11, change system settings via command line (either PowerShell or CMD) without opening Settings

The MS Settings app is an amalgamation of many different internal windows tools and APIs, which can make your overall goal pretty difficult. The only real catch-all solution is that these functions ...
  • 3,100
2 votes

To kill a CMD session

Place a * at the end of windowtitle for Windows to append something to the Window Title at process start: taskkill /f /fi "windowtitle eq countdown*"
2 votes
Accepted

More Terminals in Explorer right-click menu on Win11

"Almost": You get the option for Powershell and bash via Shift+RightClick by default. You can add/reenable the context menu "open to cmd" via registry change: open regedit goto ...
  • 8,564
2 votes
Accepted

How to suppress showing the whole current fold path in Windows terminal so that it will get as in Linux?

In PowerShell, Prompt is by default, a built-in function that returns a string. In a PowerShell session where the prompt hasn't been customized, the underlying code can be viewed by typing: (Get-...
  • 7,706

Only top scored, non community-wiki answers of a minimum length are eligible