Is it possible to permanently alter the title of a command prompt, like it is to alter the 'prompt' value? - cmd

I am aware that it is possible to permanently alter the 'prompt' variable (the command prompt that begins every command line, defaulting to the current drive and path, followed by a greater than sign (>)) in the Command Prompt by adding an Environment Variable named 'Prompt' and setting the value to that which can be set by running the prompt command.
However, I am curious to know if it is possible to set the Window Title of the command prompt (this is possible by running title [insert value here]), perhaps by setting a parameter in the cmd.exe file settings. Unfortunately I do not know if this is possible, and if so the correct syntax to get it to work. Hence my question here. I have looked in many places for an answer to this question, but I seemingly find only sites with details on command parameters being executed within the prompt itself.

There is now a way to set the title text in Windows 10 using the PROMPT variable itself, since the Windows 10 console host now recognizes ANSI control codes, but it can be a bit tricky. This is the value of my PROMPT variable:
$E]0; $p ^G$E[1;37;44m$t$s$p$g$e[0m
This gives me a prompt with the time, the current directory and a > with bold white foreground on a blue background. It also sets the window title to the current working directory.
$p and $g you presumably already know. $t inserts the time. $s inserts a space. $e inserts an ESC character. (PROMPT documentation)
$e]0; begins the ANSI sequence to set the window title. It is ended with a ^G (\007) the BEL character. This is where the tricky part lies. Setting this on the command line is trivial; you can simply type Alt+007 or hit ^G on your keyboard. Setting it in the environment variables in the registry is the hard part. The Windows edit box for environment variables ignores the control codes. I resorted to a .reg file to get it set.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"PROMPT"="$E]0; $p $E[1;37;44m$t$s$p$g$e[0m"
The ^G character shows as a square box for me here. You need to get that ^G character into that spot in the prompt string.
See the Wikipedia article on ANSI codes for more on what you can do with it.

Simpler way: Start ---> cmd ---> Right-Click ---> Open File Location ---> Right-Click "Command Prompt.exe" ---> Rename ---> ---> Enter ---> Steps 1-2 ---> Click/Right-Click+Run as administrator.
What to change through Properties
Permanent change to cmd title when you open it through Start ---> cmd ---> Left-Click/Right-Click+Run as administrator:

One can create a String key in Computer\HKEY_CURRENT_USER\Software\Microsoft\Command Processor or HKEY_CURRENT_USER\Software\Microsoft\Command Processor named AutoRun, with a value for the Window Title. This will a set the title bar of Command Prompt to the value specified in the key.

Make a registry file:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"CompletionChar"=dword:00000009
"DefaultColor"=dword:00000000
"EnableExtensions"=dword:00000001
"AutoRun"="title Hello &cls"
change autorun's value to any command, that always run at the begining. just likeÆdx said ;)

Easiest Way:
Right click on desktop and go to "new"
Click "shortcut" and type in "cmd.exe" for file location
Title it whatever you want!
(It will always have the title you selected unless you open it through the "run" box.)
Go to this link below for more help:
https://www.youtube.com/watch?v=dQw4w9WgXcQ

Related

How to set a duplicate tab keybinding in Windows Terminal

I tried to follow the Microsoft Docs instructions to set a keybinding for opening a duplicate tab with the following line { "command": "duplicateTab", "keys": "ctrl+shift+d" }, but, when I press the key combination, it opens a new tab without duplicating the position (the folder where I am) of the current tab. Here's my json file:
"keybindings":
[
...
//This makes a copy of the current tab and opens it.
{ "command": "duplicateTab", "keys": "ctrl+shift+d" }
]
I've written up a longer version of the answer to this over at https://github.com/MicrosoftDocs/terminal/pull/449. To keep it short:
Typically, the "new tab" and "split pane" actions will always open a new tab/pane in whatever the startingDirectory is for that profile. However, on other platforms, it's common for new tabs to automatically use the working directory of the current tab as the starting directory for a new tab. This allows the user to quickly multitask in a single directory.
Unfortunately, on Windows, it's tricky to determine what the current working directory ("CWD") for a process is. Even if we were able to look it up, not all applications actually set their CWD as they navigate. Notably, Windows PowerShell doesn't change its CWD as you cd around the file system! Duplicating the CWD of PowerShell automatically would almost always be wrong.
Fortunately, there's a workaround. Applications can emit a special escape sequence to manually tell the Terminal what the CWD should be.
For example, for cmd.exe:
cmd uses the %PROMPT% environment variable to configure the prompt. You can easily prepend the prompt with the command to set the CWD with the following command:
set PROMPT=$e]9;9;$P$e\%PROMPT%
This will append $e]9;9;$P$e\ to your current prompt. When cmd evaluates this prompt, it'll replace
the $e with the escape character
the $p with the current working directory

Batch wont execute but just re-print its content

No matter what my code is, even if my batch file is syntactically incorrect, even if it is absolutely correct and even if there is nothing to display on the screen the batch file when executed just displays the code as it is.
I read a similar question MSDOS prints the whole batch file on screen instead of executing but since that was on MS-DOS I hoped my issue could have a solution different than that.
Eg,
#echo off
set abcd=4
Even its batch file would just display the same lines as it is.
Please help.
Try "resetting" cmd if possible. U can try copying someone else's "cmd.exe" and replace it with yours using another bootable OS as windows wont allow that.
Here use my cmd.exe. https://drive.google.com/open?id=0B6ghonMKBfUSLVpRV0U5bG5pQTQ
Just in case u need to know I am using Windows 10 64 bit.
Check the file with an editor that allows you to see the encoding.
For example Notepad++ , you will see is very different the end of line via CF (\r) and LF (\n)
Your CMD can be recognizing EOL via \n only.
To determine whether your issue is really with line breaks being converted by your text editor (as the post you mention suggests), perform the following test:
Open a Command Line Window
Type the following command: copy con test.bat
The cursor will reposition itself under the command prompt, this is normal
Type the following 3 commands, each followed by the [Enter] key:
.
Echo Off
Set abcd=4
Echo abcd
Press CTRL-Z simultaneously (it will show up on screen as ^Z)
A confimation message should state: 1 file(s) copied.
Now type Test to run the batch file. If it runs properly, it means you are indeed dealing with line termination issues. Use a different text editor (don't use Notepad!!!), ideally one where you have an option to display the line termination characters (I personnally use NotePad++, it works great for these kinds of things but there are many others out there).
Perhaps there is a problem with your environment variables. Check the following:
Press WIN + R and run "%SYSTEMROOT%\System32\SystemPropertiesAdvanced.exe"
Click on "Environment Variables"
The system variables are listed at the bottom. Select the variable "Path" and click "Edit..."
Check whether the list contains "C:\Windows\System32" or "%SYSTEMROOT%\System32". If not, add one of those. You may have to restart your computer afterwards.

Redirection for a command in Registry

I'm trying to add a right click option to every file so that it executes a command. Seemed simple enough at first glance.
Right click option
By going in the registry editor, specifically HKCR\*\shell (which represents the context menu options that appear for every file type, hence the "*"), I added my own key as such :
HKEY_CLASSES_ROOT
*
shell
my_right_click_option
(Default) = "Click me!"
command
(Default) = my_command
Command
After this, the clickable entry appeared in the context menu instantly.
In my case, the key is called "checkmd5" and the command key's "Default" value stores the command 'my_command' to execute when clicked.
The command is :
"C:\Quite_a_long_path\md5\md5.exe" -n "%1" | clip
The -n option (an md5.exe switch) is just to remove the name of the program that gets displayed after the hash.
The %1 will be replaced by the right clicked program's path, and the double quotes are used in case any of the paths contain some whitespaces.
Sadly, all I've managed to do is execute the command (a cmd window appears and disappears, which means that the cmd has been executed) and also, just to be sure, I checked with Process Monitor (from the SysInternals Suite) the command line being executed in the small cmd window that appears and disappears and it looks like the command I put is being executed exactly as I wanted.
Nonetheless, even after appending to the command either "| clip" (to redirect output to clipboard) or "> file.txt" (to a file) [I tried using an absolute path for file too], the clipboard doesn't update, nor the file.txt gets created with the output of the command..
I can't seem to understand how to make it work..
Any help from you windows savvy will be greatly appreciated.
Thank you again for your patience, especially after getting to the end of this long post.
Turns out the only way to use the re-directions is by adding the cmd.exe /C before the command to be executed so that the command interpreter (cmd.exe) understands the redirection and not the program to be executed (aprogram.exe).
e.g:
aprogram.exe -param0 string > C:\temp\file.txt
wouldn't work, because aprogram.exe doesn't know how to manipulate redirections.
Instead it should be :
cmd.exe /C aprogram.exe -param0 string > C:\temp\file.txt

How to set different default programs in windows explorer and command line

I have some ruby scripts and i want to have 2 different default programs for a same file, one program if i double click it in windows explorer just to edit the code (for example in Sublime Text), but when i run it from command line i want the script to be executed. I am using windows 10.
So far, i have set default program for windows explorer sublime text, so the script opens just fine.
In command line i have set
E:\projects\Ruby>assoc .rb
.rb=Ruby.File
and
E:\projects\Ruby>ftype Ruby.File
Ruby.File=C:\bin\ruby200\bin\ruby.exe "%1" %*
Also i have set .RB en the PATHEXT Environment Variables so i just type the name of the script. But the problem is, when i do that, it launches Sublime Text instead of running the script.
If i change default program from windows explorer, it runs just of from command line, but of course it doesn't open sublime text if i double click it.
Is it possible to have 2 different default programs then? One form command line, and another form windows explorer when i double click some script?
It's not easy to do with GUI but it can be done through command line. First of all you have to make your association dynamic. To do it you have to use REG_EXPAND_SZ value type for registry key containing .rb file association. REG_EXPAND_SZ won't be used literally but expanded (=environment variables replaced with their actual values). You can create association with assoc but then you have to use reg add to change it because default type is REG_SZ. Program path must be something like this:
%RUBY_PROGRAM% "%1" %*
Where %RUBY_PROGRAM% is the name of - so far - not existing environment variable. Now you can give a default value to that variable:
setx RUBY_PROGRAM c:\windows\notepad.exe
Now close your command prompt and go to change its properties (from GUI). As alternative you may create a new shortcut for your modified command prompt. Command to execute has to be this:
%comspec% /k ""c:\setup_ruby.bat""
/k lets you execute given batch file at startup, in that batch you just need to set a different value for %RUBY_PROGRAM% environment variable:
SET RUBY_PROGRAM=C:\bin\ruby200\bin\ruby.exe
Now each time you run that special shortcut you will directly execute your Ruby programs. If you don't want to create a special shortcut and you want to apply this rule to every command prompt (regardless where it has been open) then you can add an entry to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun registry key.
Note that you may just put ftype in startup script (also providing a quit batch) but that will affect all applications until you close command line prompt (even if you double click file from Windows Explorer).

"edit" not a valid command in cmd.exe?

I'm trying to create a .cfg file for bcc32 compiler and I'm following the instructions. I have installed correctly and placed an environment path as instructed but when I type "edit bcc32.cfg" into the command prompt it says that edit isn't a valid command? What am I supposed to do?
You could also create a .bat file, edit.bat, to replace the 16-bit edit program (removed because x64 windows flavors won't run it) which would launch your favorite editor.
#echo off
notepad %1
#echo on
This is what I wound up doing as a simple patch so I could carry on the way I always had for the most part. Just type:
edit myfile.ext
in the command prompt to use it.
Note: notepad is not my favorite editor - this is just an example that will work with stock windows.
Note 2: #echo off and #echo on are shown for clarity. You may also shorten this by omitting the echo statements and simply placing the # before the command to be silenced.
#notepad %1
I just use notepad (since they took out the edit command) from the command window like so:
C:\Borland\BCC55\bin> notepad bcc32.cfg
The file will open in notepad for editing. When you've finished editing the file, save it and you're done.
I have found this works for seeing in-window text of a complete file, on a 64bit machine. Once your path is set in cmd prompt, type the word type... followed by "filename" do you see how I used the quotes around the filename only!
type "filename"
You type it just like this (changing filename for your files name) and you will be able to see the entire file text in the cmd window. Not sure how to edit from here on but maybe someone can figure it out from here and tell me.
Assuming you're using Windows 7 (where edit.exe and edlin.exe have been removed):
Use powershell.exe instead of cmd - thereby edit will be available via command line.
Take a look at: http://en.wikipedia.org/wiki/Windows_PowerShell
simple answer....
if your using an old version of windows (xp e.t.c...) you would be able to use edit
but since your using new version of windows, Microsoft has updated and removed the commands that they think are not relevant e.g.. (msg, edit) depending if its a bit32 bit64 or bit82...

Resources