How to make PowerShell look the same as in Windows Terminal? - windows

If I launch Windows Terminal, which, in turn, launches an instance of PowerShell 7.2.6 it looks different than if I simply launch PowerShell 7.2.6.
The top image is Windows Terminal with a PowerShell tab. Bottom image is PowerShell by itself.
Not only is the Windows Terminal version far more legible, it also renders ANSI escape codes correctly (color, cursor positioning, etc.). The stand-alone PowerShell does not.
I have confirmed, through Task Manager, that both instances are running C:\Program Files\PowerShell\7\pwsh.exe
How do I make them look the same (like under Windows Terminal) and render escape sequences in the stand-alone case?
A bit more madness...
If I take the approach of manually editing the properties of the stand-alone PowerShell to match the settings I see under Windows Terminal it makes an absolute mess. For example, if I set the font to Cascadia Mono 12, which is the setting under Windows Terminal, I get microscopic text that is unusuable:
I have to set the font size to 20 in order to approximate the look of what comes up under Windows Terminal. Also, any changes made to stand-alone PowerShell do not seem to affect PowerShell under Windows Terminal.
EDIT:
This is what Task Manager shows for these two instances. One is PowerShell launched by itself. The other is in the context of Windows Terminal. The latter does not seem to use Console Window Host.
Also, this isn't about legacy Windows PowerShell, which generally lives here:
C:\WINDOWS\system32\WindowsPowerShell\v1.0
This is about modern PowerShell, in this case version 7.2.6, which is installed here:
C:\Program Files\PowerShell\7

Note:
If you launch a console application (such as PowerShell (Core)'s pwsh.exe CLI) directly (either directly by its executable path or via a shortcut file targeting that executable path), you'll invariably (up to Windows 10) / by default (from Windows 11) get a regular (legacy) console window, backed by conhost.exe, the Windows Console Host.
Such windows have their own appearance settings, distinct from Windows Terminal's; the best you can do is to manually match them, as described in the next section.
On Windows 11, you can now configure your system to open console applications with Windows Terminal instead: in the Settings application, search for terminal and select Choose a terminal host app for interactive command-line tools
Alternatively, launch PowerShell via the Windows Terminal CLI, wt.exe, which by definition gives you the desired look and unconditional support for ANSI / VT escape-sequence rendering; e.g.:
wt.exe "C:\Program Files\PowerShell\7\pwsh.exe"
You may alternatively launch with a predefined profile, using the -p option - see this answer for more information.
Note that this invocation method isn't suitable for programmatic use of the PowerShell CLI (in case you want to execute commands unattended and receive their output).
Regular (legacy) console windows (provided by conhost.exe, the Windows Console Host) have their own font and appearance settings, distinct from Windows Terminal's; you can control them via their system menu (click on the icon in the top-left corner of the title bar and select Properties):
You can manually try to emulate the Windows Terminal look, such as by choosing the Cascadia Mono font, and it seems that size 20(!) is required to get the same on-screen size as the size 12 reported via Windows Terminal's settings. However, even then it looks like the font rendering differs slightly. You may also have to tweak the colors to match.
Note that for conhost.exe windows launched via a shortcut file (*.lnk), such as via the Start Menu and the taskbar, any modifications are saved in that shortcut file only.
Thus, to change the settings for an executable launched by direct invocation of the executable path, be sure to launch a session that way before making modifications, e.g. via the Run dialog (WinKey-R).
The modified settings are stored in the registry at [HKEY_CURRENT_USER\Console\<transformed-exe-path>], where <transformed-exe-path> is the full path of the executable with \ characters replaced with _, e.g.
HKEY_CURRENT_USER\Console\C:_Program Files_PowerShell_7_pwsh.exe
As for unconditionally rendering VT / ANSI escape sequences in conhost.exe windows: you can activate support for them in all future conhost.exe windows via the registry, by submitting Set-ItemProperty HKCU:\Console VirtualTerminalLevel -Type DWORD 1, as discussed in more detail in this answer.

Related

Can I have multiple Powershell Consoles in one window?

So, now I have many open apps, often 3-4 powershell consoles. I'm able to order the powershell windows to watch them together (top left, top right, bottom left, bottom right).
So this means that if I switch to another app, when I switch back I have to restore all multiple powershell windows to see them all again.
What I want is, to create only one 'shared window' for many powershell, because when I need one, I need all of them to see.
Is there a way to do this?
Just to add more details about Windows Terminal approach:
Open a Windows Terminal
Type Alt+Shift+= or Alt+Shift+- to open a new Pane in the same tab
Type Shift+Ctrl+W to close the current Pane
If you need more details or modify the settings, go to next page Panes in Windows Terminal
ConEmu has this option.
You can also configure it to open as much consoles as you want when it starts.
ConEmu website
Enjoy!
VSCode can have Multiple Terminals which is the closest to this I've seen, quoted from documentaion:
You can create multiple terminals open to different locations and easily navigate between them. Terminal instances can be added by hitting the plus icon on the top-right of the TERMINAL panel or by triggering the Ctrl+Shift+` command. This creates another entry in the dropdown list that can be used to switch between them.
You can also split the terminal by triggering the Ctrl+\ command or via the right click context menu
Windows now provides the Windows Terminal.
Windows Terminal can split the terminal into panes and can also run different shells (i.e. cmd, powershell, and bash through the wsl)
You can install Windows Terminal directly from the Windows Store.
Create a virtual machine where you can run your PowerShell sessions uninterrupted. The PowerShell windows are always where I placed them when I come back.
It could be an expensive solution depending on your needs, but I have been doing this a long time. It's a robust solution since the only user processes on the VM are my PowerShell sessions.

CMD has wrong encoding when launched from the Run dialog

Some time ago I had to change my system locale from Czech (default) to Japanese because I needed to run some Japanese programs that would otherwise crash.
The problem is, after switching back to Czech, my command prompt would launch with the Shift-JIS encoding whenever I opened it from the Win+R dialog (which is my preferred way of launching cmd). It would also draw characters in a strange bloated font. The problem persists even after uninstalling Japanese from my system altogether.
If I open cmd any other way (Start menu, Right-click Start -> Command Prompt, cmd.exe...), everything works correctly. All settings that I could think of are set to Czech:
System locale
Language for non-Unicode programs
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage (OEMCP value)
Another thing is that Regedit always opens on HKEY_CLASSES_ROOT\MIME\Database\Codepage, though I don't know if that's related to the problem.
I'm running Windows 10, after the free upgrade from 8.1 and 7. Picture shows the different cmd windows.
http://i.imgur.com/jyyhAOA.png
Settings are stored a number of places. Look here for a codepage value and delete it.
HKCU\Console\%SystemRoot%_system32_cmd.exe\

How to Launch a Metro App from Microsoft Access VBA on Windows 10 Computer

I have a situation in which I wanted to utilize the camera app in Windows 10 from my Microsoft Access program. Normally I could just send a command to execute the program's executable, but with the metro app there is no straightforward executable.
The basic code I use is this:
Shell """" & PthToExe & """", vbNormalFocus
PthToExe is the path name for the executable.
I looked around a decent bit, but was unable to find any simple solutions and ended up coming up with my own. My solution is to make a shortcut link to the camera application and then to launch the link.
In order to make a shortcut link in Windows 10, you can click on the start button, go to "All Apps", find the app you want (in my case "Camera"), and then click and drag it to the desktop.
Now that you have a shortcut, you can launch the shortcut from a command line. (So my shortcut doesn't clutter up my desktop, I dragged it off my desktop and into a folder on the "C" drive.)
Type the path into a command prompt like this and hit enter to test launching your app: C:\GJ\Camera.lnk
So that solves the problem if you wanted to launch from a command line. For some reason, though, Access would not accept that command. The way I got around it was I put the command in a batch file (Edit: Alternatively, see HansUp's comment). To do that, you just need to open notepad, type in the same thing you typed in the command prompt, save the note pad document, and then rename the document to have a .bat extension.
You can then execute the .bat file from Microsoft Access as follows:
Shell "C:\GJ\OpenCamera.bat", vbMinimizedNoFocus
Note that normally, I use vbNormalFocus when running the shell command, but in this case, it is desirable not to see the little command prompt open before the actual program opens.

How to change the path for "run command" "notepad"?

Where is in the registry the path executed when I run the "notepad" command in windows "Start->run command" interface? I want to change it for notepad++ (it is required so, although could look not really good)
If you are like me you use windows run command all the time. I hate using the mouse to point and click a shortcut on the start menu. WIN-R are probably the two most over used keys on my keyboard. After thinking about if awhile I hunted down how the run command works. It turns out that it makes a call to ShellExecute, which I guess is not too surprising. The next thing I wanted to find out was exactly how the commands are resolved. The following is an ordered list of how they are resolved ([1]):
The current working directory
The Windows directory (no subdirectories are searched)
The Windows\System32 directory
Directories listed in the PATH environment variable
The App Paths registry key
Naturally the next thing I wanted to do was customize existing commands or add new commands so I do not have to type as much (standard lazy approach). After examining my options which were to put the executable in one of those paths (since it only locates executables and not shortcuts), modify the path environment variable or add a key to App Paths. The App Paths option seems to be the easiest and most flexible to me. Here is a layout of what you need to do to add an App Paths entry ([1]):
HKEY_LOCAL_MACHINE-->
SOFTWARE-->
Microsoft-->
Windows-->
CurrentVersion==>
App Paths-->
file.exe-->
(Default) = The fully-qualified path and file name
Path = A semicolon-separated list of directories
DropTarget = {CLSID}
Disclaimer: Modifying the registry can cause serious problems that may require you to reinstall your operating system. I cannot guarantee that problems resulting from modifications to the registry can be solved. Use the information provided at your own risk.
The minimum needed to add a new entry is to add the key file.exe where file is the string you want to type into the run command and to add the Default entry which is the fully-qualified path to the file you want to execute. Note that even it the file you are going to reference isn't an exe file you still need to put the .exe on the key. Here is a sample registry file that I created to add a shorter keyword for Internet Explorer:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\ie.exe] #="C:\Program Files\Internet Explorer\iexplore.exe"
After entering that entry into the registry I can simply type “ie” at
the run command to open internet explorer.
Here is a list of some common commands I use at the run command:
cmd – Command prompt winword – Microsoft Word excel – Microsoft Excel
outlook – Microsoft Outlook iexplore – Internet Explorer firefox –
Mozilla Firefox notepad – Notepad compmgmt.msc – Computer Management
Console control appwiz.cpl – Add/Remove programs dialog mstsc –
Microsoft Terminal Service Client regedit – Registry Editor
…
If there is some program that I find myself using all the time I figure out what the run command is for it and if there is not a short easy one I add one to my App Paths as described above. Does anyone else have some other common run commands they use?

As a developer, what changes do you make to a vanilla Windows install?

When I get a vanilla Windows system, there's a bunch of stuff I change to make it more developer-friendly.
Some of it I remember every time, other stuff I only do as and when.
Examples:
Show extensions of all file types
Make hidden and system file visible
Turn off Windows Defender
I seem to remember a blog post from Jeff on this topic, but can't locate it!
What else do you do, and do you have any tools that automate this process?
Indeed I do the above, plus deactivating Zip support (regsvr32 /u zipfldr.dll), activating the underscore on Alt shortcuts (Advanced Appearance), replacing Courier New by Andale Mono (replace with your favorite font) in all program settings (after installing it, of course), installing my favorite utilities (UnxUtils, Sysinternals', SciTE, FileMenu Tools which has Command line here and lot of other goodies, etc.) and so on.
Oh, and indeed also deactivate dual keyboard support (French/English), deactivate task grouping, install VirtuaWin (4 desktops), CLCL (clipboard manager), AutoHotkey and my favorite macros, and lot of other freewares, more or less must have.
No automation, alas.
I install Cygwin to have *nix command line tools and Xemacs to have a useful editor.
I install:
The usual suspects: Visual Studio, Sql Management Studio, Firefox, Chrome, etc...
Paint.Net
Notepad++
Launchy
The first thing I do is open a command prompt and then open the properties for it:
Switch on Quick Edit. Why is this off by default?
Increase the window size. Why limit it to the size of a postage stamp?
Increase the vertical buffer to the maximum possible. Why limit it to a few hundred lines?
Change the foreground colour to white instead of grey. Why make it less readable than it could be?
In summary: WHY?
Using the Add\Remove Windows Components in Control Panel, I always remove...
Games
Document Templates
MSN Explorer
Outlook Express
For the look and feel I...
Revert to the classic start menu; however, if it's Vista, I leave it as is because I like the indexed search feature.
Revert to a classic desktop with large icons and make sure that My Computer is the first icon (versus My Documents)
I also perform the things you mentioned above
Before installing any software I...
Install any outstanding Windows updates
Run a Disk Clean Up
Run Disk Defrag
Setup scheduled tasks for Clean Up, Defrag, and other personal tools
For tools (outside of my IDEs and other necessary development tools), I install..
TweakUI
IE6, IE7, Safari, Chrome, Opera, and Firefox
Install the set of Firefox plug-ins I always use for development
'Open Command Prompt Here' shell extension
Install Consolas and set it as the default font for my editors (IDEs, Notepad++, etc)
I wipe it and install Linux. Everyone is always amazed by how productive I can be. It's because I don't spend half my time fighting with the machine.
Install Consolas font and turn on (and tune) ClearType.
Install ZoomIt to magnify display during presentations.
Install FireFox/Firebug
Install XYplorer Win Explorer alternative (can't live without it!)
Install DeskPins to be able to make any Window temporarily topmost.
Make sure OneNote got installed with Office.
Install Visio.
Install favorite editor (whatever it is at the time, currently SCiTE).
Install 7Zip.
Fix Windows colors to suit me and put picture of RatPack (Dean's my hero) as wallpaper.
Disable shortcuts to FilterKeys, StickyKeys, and ToggleKeys - nothing frustrates me more than having to deal with that cruddy feature because I push the shift key down several times while I'm thinking or hold it down for eight seconds (again, while thinking) before I start typing!
Change the default action for Folder to explore instead of open.
over the years i have arrived to the decision that i do as little customization as possible since workplaces change and computers change (both at home and at work).
i used to do all kinds of crazy tweaks with litestep, setting up partitions, etc. these days i pare it down to the basics, and it does not take me long to setup a machine and have a familiar environment.
in addition to the usual "win32dev" setup (classic scheme, optimized for performance, no special effects, show all files, details in explorer views, blue background, etc) i have the following stack:
cygwin (gcc, vim, curl, wget, perl/ruby/python, svn, git, ssh, netcat, etc; rxvt for terminal)
ffox + adblock + dev plugins
clipx for simple stack-like clipboard with previews
textpad + a few basics syntax highlighters
virtuawin - the only minimal window manager that does all i need and nothing more
autoHotKey for basic app shortcuts
procexp to replace task manager
all other sysinternals tools
tortoise svn
putty + agent + keys
7zip
keepass
wireshark
everything i install by hand goes into c:\programs (for easy no-space, lowercase paths).
Regarding:
Show extensions of all file types
Make hidden and system file visible
I don't like making hidden files visible all the time (it makes two desktop.ini visible on my windows Vista desktop for starters) so I use an explorer extension to make it easy to toggle this on and off. There's also a corresponding one for file extensions:
HiddenFilesToggle Context-Menu Shell Extension
FileExtensionToggle Context-Menu Shell Extension
Command line scripts
For storing scripts that I use from the command line I create a Command Line Scripts directory under Program Files and add it to the PATH environment variable. I use the following batch file for listing and editing those scripts:
#echo off
setlocal
set UTILPATH=C:\Program Files\System Tools\Command Line Utilities
if not "x%1"=="x" (
start "" "notepad" "%UTILPATH%\%1.bat"
) else (
dir /b "%UTILPATH%" | grep -v com.bat | grep -P "(exe|bat|cmd)" | sed "s/\.\(exe\|bat\|cmd\)//"
echo.
)
(note that the filtering of the directory listing depends on some unix commands I have installed via Cygwin)
I give it the name com.bat, (short for command) then I can:
list the scripts in that directory by typing com at the command prompt
edit any script in the list by typing com script-name at the command prompt*, similarly:
create new scripts in that directory by typeing com new-script-name at the command prompt*
and if I ever need to edit com.bat I just type com com
* As I'm running Vista I have to use an elevated command prompt as directories under Program Files are protected.
For a quick way to launch an elevated command prompt, simply press the Win key; type cmd; press Ctrl+Shift+Enter; and then hit Alt+C to confirm the elevation prompt. Six keystrokes to an elevated command prompt! ([via][4])
Startup Script
One of the scripts I store in my Command Line Scripts directory is a script that is run when I log in to windows (via the Task Scheduler, type Task in the Vista start menu). I use that script to set up several virtual drives using the subst command to directories I access frequently or want a quick way to access on the command prompt or for shortening path names in compiler warnings, logs or debug output.
My Startup script looks something like this:
#setlocal
#set _MYDOCS_=%USERPROFILE%\Documents
#REM Note: first delete the drives so I can run script again
#REM to fix drives that failed to get mapped
subst /d W:
subst /d T:
subst /d S:
subst /d R:
subst /d N:
subst /d L:
subst /d H:
subst W: "%_MYDOCS_%\Work\SVN Working Copy\Website\trunk\www"
subst T: "%_MYDOCS_%\Work\SVN Working Copy\project 1\trunk"
subst S: "%_MYDOCS_%\Work\SVN Working Copy"
subst R: "%_MYDOCS_%\Work\SVN Working Copy\project 2\branches\12.50"
subst N: "%_MYDOCS_%\Work\SVN Working Copy\project 2\trunk"
subst L: "%_MYDOCS_%\Work\"
subst H: "%_MYDOCS_%\My Projects\Haslers.info\Working Copy"
Note that subst can be a little temperamental and occasionally the drives don't get created and I have to run the startup script again manually.
I'm surprised nobody has mentioned ClipX. I find that I can't develop without this clipboard history tool.
Step 1: Fix windows
Turn off System Restore
Turn off Windows Defender
Uninstall any OEM-supplied antivirus or other crapware if it's an OEM box
Get SysInternals AutoRuns and lay the smackdown to all the 8000 useless startup items and services vista inflicts upon you, including the slow and useless vista search indexing service.
Step 2: Install stuff.
Now that my shiny new Core 2 Duo PC isn't bogged down with useless crap running like a 386, I can build it up again
Install Firefox
Install FlashPlayer firefox plugin (why oh why isn't this bundled with FF?)
Run windows update and let it do it's download/reboot cycle 50 times until it's happy
While this is happening I can use firefox to browse stackoverflow and read reddit :-)
Get UnixUtils and either unzip them to system32, or otherwise make sure they are in the path.
This is neccessary because I can't stand cygwin, yet my muscle memory keeps typing ls when I try to type dir, and windows still hasn't heard of grep yet
Install Droid Sans Mono and Monaco fonts for programming
Install E-TextEditor
If I'm installing visual studio, do that. If not install the .NET framework runtime instead
Install Firefox addons (firebug, fission, web developer, adblock)
I add Wordpad to the Send To context menu. Instructions for XP here. Works in Vista, as well.
Someone gave me a 'Delete all SVN folders' registry script - that is a must have for me, now (it's somewhere on this thread).
I leave UAC on - last thing I want is to write code that works with UAC off, but fails miserably with it on. Before I started to use Virtual PC to set up test environments for my code, I tried to leave my desktop as 'vanilla' as possible - I wanted to test under conditions reasonably similar to an everyday non-developer user.
All of the above is for my home development system. I try to do the same at work, within reason. Except for the SVN stuff, because we use TFS at my office.
I always install the following to make it easier to manage and interact with windows
Taskix - Reorder buttons in your Windows taskbar
KatMouse - scroll the window directly beneath the mouse cursor
WinSplit Revolution - organize your windows by tiling, resizing and positioning them
allSnap - windows automatically snap to window edges and (optionally) the edges of other windows
I like to:
Make the taskbar larger so that it can hold two rows of applications
Disable personalized menus in the start menu
Disable grouping of similar taskbar items
I also randomly open a lot of PuTTY sessions to various machines, so I like to create a "bin" directory in my home folder, add it to the PATH, and then create a shortcut to PuTTY in it named "p" (among other shortcuts). I can then easily Windows-R (run) and type p [putty-session-name] to open the session. This has saved me tons of time / mouse clicks.
I follow the extensive recipe for making a Windows system useful built and maintained by Simon Peyton Jones.
Turn off Autorun so that I'm not accidentally installing malware or crapware.
Here's a couple of links, out of many:
http://antivirus.about.com/od/securitytips/ht/autorun.htm
http://news.cnet.com/8301-13554_3-9894970-33.html?tag=mncol;txt
Couple of things no-one else mentioned
Install Console2 for tabbed cmd windows
Install Powershell
Completely replace Notepad with Notepad2
Install the full IIS.
Set the resolution high enough.
Set the background to Grey.
Show hidden and system files.
Toolbar 2 or 3 high (I run one monitor sideways).
Always show file extentions.
I install some set of *nix command utilities and process explorer at a bare minimum.
Also, on XP systems I disable any theming and use the windows classic coloration. Vista just doesn't look or work right without the Aero theme so I can't do that on Vista without going almost completely nuts.
Also forgot, I install Chrome. (Used to be Firefox but Chrome is nicer out of the box)
I use nLite to prepare the windows installation disk in order to have some typical settings already set right after the installation.
For example:
Explorer-Associate additional file types with Notepad
Explorer-Classic Control Panel
Explorer-Disable Beep on errors
Explorer-Disable Prefix: Shortcut to
Explorer-Show extensions of known file-types
Explorer-Show hidden files and folders
Explorer-Show the full path in the Title Bar
Performance-Disable Info Tips on Files and Folders
Performance-Disable Last accessed Timestamp on files
Taskbar-Disable Group similar Taskbar buttons
Taskbar-Disable Language-Bar
Taskbar-Lock the Taskbar-Yes
You can also remove useless parts of the system:
Accessibility Options
Briefcase
ClipBook Viewer
I install all of the shell extensions I normally use (TortoiseSVN and CommandHere for example).
Also, one of the first things I do after I reimage a machine is make sure it's hooked to all of my network shares properly. Few things derail my work as quickly as having to fight with the network to get a file at an inopportune time.
Install emacs + a selection of gnuwin32 packages.
Also proexp to replace task manager.
Edi Weitz has a nice writeup of his customizations: Making Windows usable for old Linux farts
Switch to classic menu
Increase the taskbar hight to have more shortcuts & lock the taskbar
Performance options -> Adjust for best performance
Copy all the backed up shortcuts files to Favorites folder
Install necessary software (JDK, DBMS stuff, Editplus, MS Office etc.)
Driver for soundcard
New network connection for Broadband ...
I generally leave Windows Defender online but I don't use an antivirus so....
I set my start menu to display small icons and to have no "most recently used programs" active. Instead I pin everything to my start menu:
My start menu http://www.robpaveza.net/pub/startmenu.png
I also make sure that all the extension menus are actual menus, not just links, and that my computer and user files icons are shown on the desktop.
I download and install Cygwin and Xming.
Wow, this is a really good thread... I'm going to have to go through all the suggestions and see what I'm mission out on :)
Off the bat, I install:
Google Chrome
Visual Studio 2008
aShampoo CD Burning suite (or whatever my current favorite burning suite is)
IZArc (or whatever my current favorite is)
RocketDock - I use it to replace Quick Launch.
Songbird
When I used XP (I'm on Vista now) I'd always install Tweak UI and tweak everything to my liking. Like listing My Computer before My Documents.
I remove the Help icon from the start menu.
I make it so Network Neighborhood was displayed in the start menu.
I have it show file extensions and show hidden files/folders.

Resources