The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,856 other followers

Archive for the ‘Console (command prompt window)’ Category

How can you export the Visual Studio Code extension list? (via: Stack Overflow)

Posted by jpluimers on 2022/06/16

Adapted from [Archive.is] How can you export the Visual Studio Code extension list? – Stack Overflow, presuming that code is on the PATH:

  1. From the command-line interface on MacOS, Linux, BSD or on Windows with git installed:
    code --list-extensions | xargs -L 1 echo code --install-extension
  2. From the command-line interface on MacOS, Linux, BSD or on Windows without git installed:
    code --list-extensions | % { "code --install-extension $_" }

    or, as I think, more clearly (see also [WayBack] syntax – What does “%” (percent) do in PowerShell? – Stack Overflow):

    code --list-extensions | foreach { "code --install-extension $_" }

    or even more explanatory:

    code --list-extensions | ForEach-Object { "code --install-extension $_" }
  3. From the command-line interface on Windows as a plain cmd.exe command:
    @for /f %l in ('code --list-extensions') do @echo code --install-extension %l
  4. On Windows as a plain cmd.exe batch file (in a .bat/.cmd script):
    @for /f %%l in ('code --list-extensions') do @echo code --install-extension %%l
  5. The above two on Windows can also be done using PowerShell:
    PowerShell -Command "code --list-extensions | % { """""code --install-extension $_""""" }"

    Note that here too, the % can be expanded into foreach or ForEach-Object for clarity.

All of the above prepend “code --install-extension ” (note the trailing space) before each installed Visual Studio Code extension.

They all give you a list like this which you can execute on any machine having Visual Studio Code installed and its code on the PATH, and a working internet connection:

code --install-extension DavidAnson.vscode-markdownlint
code --install-extension ms-vscode.powershell
code --install-extension yzhang.markdown-all-in-onex

(This is about the minimum install for me to edit markdown documents and do useful things with PowerShell).

Of course you can pipe these to a text-file script to execute them later on.

The double-quote escaping is based on [Wayback/Archive.is] How to escape PowerShell double quotes from a .bat file – Stack Overflow:

you need to escape the " on the command line, inside a double quoted string. From my testing, the only thing that seems to work is quadruple double quotes """" inside the quoted parameter:

powershell.exe -command "echo '""""X""""'"

Via: [Archive.is] how to save your visual studio code extension list – Google Search

–jeroen

Posted in *nix, *nix-tools, .NET, bash, Batch-Files, CommandLine, Console (command prompt window), Development, Mac OS X / OS X / MacOS, Power User, PowerShell, PowerShell, Software Development, Visual Studio and tools, vscode Visual Studio Code, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Development, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016, WSL Windows Subsystem for Linux, xargs | Leave a Comment »

Windows: get CPU information on the console

Posted by jpluimers on 2021/12/28

It still seems that WMIC is the quickest way to get CPU information on the console:

T510-PSO C:\bin\rdp> wmic cpu get name,CurrentClockSpeed,MaxClockSpeed
CurrentClockSpeed  MaxClockSpeed  Name
2667               2667           Intel(R) Core(TM) i5 CPU       M 560  @ 2.67GHz

T510-PSO C:\bin\rdp> wmic path win32_Processor get Name,NumberOfCores,NumberOfLogicalProcessors
Name                                             NumberOfCores  NumberOfLogicalProcessors
Intel(R) Core(TM) i5 CPU       M 560  @ 2.67GHz  2              4

Actually, wmic cpu is shorthand for wmic path win32_Processor, so this works fine:

T510-PSO C:\bin\rdp> wmic cpu get name,CurrentClockSpeed,MaxClockSpeed,NumberOfCores,NumberOfLogicalProcessors
CurrentClockSpeed  MaxClockSpeed  Name                                             NumberOfCores  NumberOfLogicalProcessors
2667               2667           Intel(R) Core(TM) i5 CPU       M 560  @ 2.67GHz  2              4

The reason is that cpu is an alias:

T510-PSO C:\bin\rdp> wmic alias cpu list brief
FriendlyName  PWhere              Target
CPU           Where DeviceID='#'  Select * from WIN32_PROCESSOR

Via:

–jeroen

Posted in Batch-Files, Console (command prompt window), Development, Power User, Scripting, Software Development, T510, ThinkPad, Windows | Leave a Comment »

Opening shell folders from the command-prompt

Posted by jpluimers on 2021/09/09

I knew I could run shell:startup and similar shortcuts from the Explorer address bar or the Windows-R “run” prompt.

First I learned that via [WayBack] tablet – How to set Google Chrome to automatically open up and in full screen – Super User.

Then via [WayBack] “shell:startup” – Google Search, I found [WayBack] Location of the Startup folder in Windows 10.

It took a while before I realised you can also run them from the command-prompt, batch-files or PowerShell scripts prepending them with start:

start shell:startup

That one will open a new explorer window in the user startup folder from either the command-prompt, a batch file or PowerShell script..

The shell: shortcuts can contain spaces. So for instance there is shell:common startup that opens the common startup folder.

Starting it from the command prompt, batch file or PowerShell script is different: because of the spaces you will get the error on the right unless you add double quotes:

start "shell:common statartup"

All shell: commands that you can run in the same way: double quotes work for both the ones requiring spaces and the simple ones nor requiring spaces.

Virtually each new Windows version (even most Windows 10 major builds) gets new shell: commands.

A good source with an up-to-date and historically accurate of shell: commands list is at [WayBack] Shell Commands to Access the Special Folders in Windows 10/8/7/Vista/XP » Winhelponline,

You can get the current list by recursively enumerating the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions registry key, which consists of a list of Explorer folder GUIDs having Name, ParentFolder and RelativePath value names.

–jeroen

Read the rest of this entry »

Posted in Batch-Files, Console (command prompt window), Development, Power User, Scripting, Software Development, Windows | Leave a Comment »

Windows command prompt: decrementing loop

Posted by jpluimers on 2020/12/30

I needed a decrementing loop on the Windows command prompt, but that seems very hard from batch files without programming your own kind of while loop:

PowerShell to the rescue to loop back from and including 463 down to and including 290:

PowerShell -Command "for ($i=463; $i -ge 290; $i--) { Write-Host "Value " $i}"

This outputs:

Value 463
Value 462
...
Value 291
Value 290

In a similar way, you can execute a cmd command, but then you need to be careful on how to pass parameters: the \" is important to you can have quotes within quoted strings..

PowerShell -Command "for ($i=463; $i -ge 290; $i--) { & echo \"Value $i\"}"

gives this:

Value 463
Value 462
...
Value 291
Value 290

Read the rest of this entry »

Posted in Batch-Files, CommandLine, Console (command prompt window), Development, PowerShell, PowerShell, Scripting, Software Development, Windows | 1 Comment »

When NTFS shrink fails, despite using the default settings from the shrink dialog

Posted by jpluimers on 2020/05/25

Sometimes an NTFS shrink still fails, even though you use the built in Windows defragmentation tools, of SysInternals contig tool.

The best you can do is to follow the steps in:

  1. run diskmgmt.msc to try shrinking the disk, then often it is already in the error message: “You can’t shrink a volume beyond the point where any unremoveable files are located see the defrag event in application log for detailed information about the operation when it has completed.”
  2. use eventvwr.exe and look at the Windows Logs for the most recent Application entries that has Source set to defrag

Those defrag entries usually tell about the last file that could not be moved.

You can use wevtutill to query events on the commandline.

Note that contrary to [WayBack] WEVTUTIL – Windows CMD – SS64.com documentation, the option /rd cannot be expanded to /reversedirection , as you will get an error “invalid option reversedirection” – Google Search.

For querying the above defrag event, use this command line (replace /format:XML with /format:text for more readable but also more verbose output):

wevtutil query-events Application /count:2 /format:XML /rd:true /query:"*[System[(EventID=259)]]"

On Windows 10, this is often caused by “System Protection” which locks files under C:\Recovery, but I have also seen $BITMAP, $MFT and $DATA entries.

System protected drives

To view which drives are currently used for system protection (this opens the “System Properties” dialog focussed on the “System Protection” tab):

SystemPropertiesProtection.exe

To disable it for one drive:

Disable-ComputerRestore -Drive "C:"

To enable it for one drive:

Enable-ComputerRestore -Drive "C:"

There seems to be no easy one-command PowerShell way to view the drives have ComputerRestore enabled, as this does not show drive letters:

PowerShell Get-ComputerRestorePoint ^| Format-List

The above gives more detailed output than a plain PowerShell Get-ComputerRestorePoint

Deleting restore points

PowerShell does not have a built-in option to delete restore points, but vssadmin has, but calls them “shadows”.

First list them:

vssadmin list shadows

Then delete them (but be aware this will not prompt for confirmation because of the /quiet):

vssadmin delete shadows /for=C: /quiet

You can also delete them for all drives (this will not prompt for confirmation either):

vssadmin delete shadows /all /quiet

Stopping the volume shadow copy service:

net stop vss

Managing hibernation and page file

Hibernation:

powercfg.exe /hibernate off

powercfg.exe /hibernate on

Page file:

wmic pagefile list /format:list
AllocatedBaseSize=2944

CurrentUsage=0
Description=C:\pagefile.sys
InstallDate=20181018215808.683376+120
Name=C:\pagefile.sys
PeakUsage=0
Status=
TempPageFile=FALSE

wmic computersystem where name="%computername%" get AutomaticManagedPagefile
AutomaticManagedPagefile
TRUE

wmic computersystem where name="%computername%" set AutomaticManagedPagefile=False
Updating property(s) of '\\MYCOMPUTER\ROOT\CIMV2:Win32_ComputerSystem.Name="LAPTOPUW08"'
Property(s) update successful.

wmic computersystem where name="%computername%" get AutomaticManagedPagefile
AutomaticManagedPagefile
FALSE

wmic.exe pagefileset where name="C:\\pagefile.sys" delete
Deleting instance \\MYCOMPUTER\ROOT\CIMV2:Win32_PageFileSetting.Name="C:\\pagefile.sys"
Instance deletion successful.

Sometimes the deletion does not work (see below for workaround):

wmic pagefile list /format:list

AllocatedBaseSize=2944
CurrentUsage=0
Description=C:\pagefile.sys
InstallDate=20181018215808.683376+120
Name=C:\pagefile.sys
PeakUsage=0
Status=
TempPageFile=FALSE

Do not do this:

wmic pagefile delete
Deleting instance \\MYCOMPUTER\ROOT\CIMV2:Win32_PageFileUsage.Name="C:\\pagefile.sys"
ERROR:
Description = Provider is not capable of the attempted operation

wmic pagefileset set name="c:\\pagefile.sys",InitialSize=0,MaximumSize=0
No Instance(s) Available.

Sometimes it still fails, so then you have to use the UI:

  1. Run SystemPropertiesAdvanced.exe
  2. Under Performance, click on Settings
  3. Click the Advanced tab
  4. Under Virtual memory, click the Change button
  5. Ensure Automatically manage page file size for all drives is disabled
  6. Ensure No paging file is selected
  7. Click the Set button
  8. Confirm you really want no page file
  9. Press on the three OK buttons to fully leave the Advanced System Properties dialog.
  10. Reboot

After resizing the disk, reverse the steps:

  1. Run SystemPropertiesAdvanced.exe
  2. Under Performance, click on Settings
  3. Click the Advanced tab
  4. Under Virtual memory, click the Change button
  5. Ensure Automatically manage page file size for all drives is enabled
  6. Confirm you really want no page file
  7. Press on the three OK buttons to fully leave the Advanced System Properties dialog.
  8. Reboot

Bitmap file

Sometimes the file blocking the resize is the NTFS "\$BitMap::$DATA", which few defragmentation tools can move as it is the MFT Bitmap.

Background reading

–jeroen

Posted in CommandLine, Console (command prompt window), Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »

 
%d bloggers like this: