Tag: windows command line

ImageMagick error on Windows: “magick: unable to open image ”test’: No such file or directory @ error/blob.c/OpenBlob/3565. magick: no decode delegate for this image format `’ @ error/constitute.c/ReadImage/741.” (SOLVED)

If in Windows 11 open CMD:

cmd

And then run the command:

magick '.\Для теста.jpg' test.png

An error will be received that there is no such file or directory:

magick: unable to open image ''.\╨Ф╨╗╤П': No such file or directory @ error/blob.c/OpenBlob/3565.
magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741.

You can see that non-Latin characters are used in the file name, so you might think that this is the problem – that is, the “magick” program does not support alphabets other than English.

But if you try to rename the file and run the following command:

magick 'test file.jpg' new.png

Then the same error will be received again:

magick: unable to open image ''test': No such file or directory @ error/blob.c/OpenBlob/3565.
magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741.

How to fix “magick: unable to open image ''test': No such file or directory @ error/blob.c/OpenBlob/3565. magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741.”

1. Use double quotes instead of single quotes

If the filename is enclosed in double quotes instead of single quotes, then the command works correctly:

magick ".\Для теста.jpg" test.png

That is, try putting the filename in double quotes. If the problem persists, then it is related to the encoding of the file name.

2. Use PowerShell instead of CMD

In Windows 11 and Windows 10, the default command prompt is PowerShell, not CMD.

If your Windows uses CMD by default, then either set it to use PowerShell in the settings, or run one of the following commands at the command prompt:

powershell
pwsh

In Windows 11 + Windows Terminal Preview + PowerShell 7 command

magick '.\Для теста.jpg' test.png

works without errors.

See also: ImageMagick guide: installing, using, and troubleshooting

Basics of launching and using command line utilities in Windows

Are the command line and command line utilities relevant today?

Windows users are accustomed to using programs (applications) with a graphical user interface, in which actions are performed using mouse clicks or keyboard input.

At the same time, even in Windows there are and can be installed many utilities, programs without a graphical interface, with very useful functionality. As a rule, programs without a graphical interface are designed to perform a highly specialized action or function and are designed for professionals.

Programs without a graphical interface are called “command line utilities”, “programs with a command line interface” (CLI).

There is no need to think that command line utilities are some kind of atavism and something outdated. This is very far from the truth! Entire layers of specialized programs in various fields are developed precisely as utilities with a command line interface.

The purpose of this note is to give a general idea to Windows users about how to deal with the command line. If you have downloaded the utility and cannot run it, then this note is for you!

When I click on the exe file, a black window flickers and then disappears

When you try to launch the command line utility by double-clicking, you will most likely encounter the console window flashing for a second, which immediately closes.

Programs with a command line interface are not designed to be launched by double-clicking. Instead, they need to be run, as you might have guessed, on the command line.

Windows has several environments for executing commands:

  • CMD
  • PowerShell (includes all the features of CMD and provides many cmdlets for administering Windows desktops and servers)

You can also remember Windows Terminal, but this is not a separate environment that has its own commands, but just an application for conveniently entering CMD and PowerShell commands.

To run the program, you need to open a Windows Terminal window (or PowerShell). To do this, press the key combination Win+x, and select “Windows Terminal” or “Windows Terminal (Admin)”:

What to choose: “Windows Terminal” or “Windows Terminal (Admin)”

Utilities can be run with normal user rights, or require running with Administrator rights.

With Administrator rights, for example, the following programs should be launched:

  • Programs that register and install themselves as system services
  • Programs that require low-level access to devices (for example, programs for partitioning or fixing disk errors)
  • Programs that change system settings that only an administrator can change.

An example of programs with a command line interface that require Administrator rights:

  • Apache (web server, it registers and starts itself as a system service)
  • MySQL (DBMS, it registers and starts itself as a system service)

An example of utilities that do not require elevated privileges:

How to run an executable on the command line

Consider running a program with a command line interface using the Apache web server (httpd) as an example.

The first option: you can simply drag and drop the executable file into the command line window. The Apache executable is httpd.exe.

The second option: on the command line, you can change the current working directory to the one where the Apache executable files are located. For example, my program is located in the C:\Apache24\bin\ folder, to change the current working folder, the “cd” command is used, after which the folder you want to go to is indicated, in my case the command looks like this:

cd C:\Apache24\bin\

As you can see from the screenshot, the C:\Users\MiAl folder has been changed to C:\Apache24\bin\.

Now, to run the program, it is enough to type the name of the executable file indicating the current folder. The current folder is indicated by a dot (.), then you need to put a backslash, it turns out like this:

.\httpd.exe

Apache is a network service, that is, a program that uses a computer network for its work. Specifically, Apache listens for incoming connections on port 80 (the service opens a port). For this reason, the Windows Firewall asks whether to allow the Apache HTTP Server program to communicate on the network, select “Allow access”.

Already at this stage, the web server is running, and you can open the address http://localhost/ in a web browser

To stop the service, press Ctrl+c.

How to get help using the utility

Typically, command-line utilities support various options that can be specified with a space after the executable file name.

Also, utilities usually have built-in help on available options, which can be displayed using the -h option or the --help option, which must be specified after the executable file name.

For example:

.\httpd.exe -h

In addition to command line options, many services are configured using configuration files, which are text files with a specific syntax. This is especially common for utilities that came to Windows from Linux, since in this operating system many programs are configured using text files.

In this case, quite often explanations of custom directives are contained in the configuration file itself in the form of notes, or in accompanying documentation.

README, ReadMe.txt, README.md files and software documentation

Utilities are usually accompanied by documentation. For example, this is an Apache archive:

As you can see, the ReadMe.txt file with documentation is attached to the archive – this is documentation from those who compiled Apache for Windows.

Inside the Apache24 folder there are even more files and folders with installation information and more.

This is a PHP archive – it also contains a README.md file that provides help information.

A MySQL archive containing a README file and a documentation folder or a link to the documentation.

Program in PATH environment variable

The above shows that in order to run the program, you need to go to the folder with this program.

Alternatively, you can specify the full path to the executable, for example:

C:\Server\bin\Apache24\bin\httpd.exe

It is this method that works when you drag and drop the utility into the console to run the utility – in this case, the full path to the file is inserted into the command line.

But some commands run from any folder, wherever you are on the command line. For example, try the following command:

find /?

The fact is that for operating systems there is such a thing as the PATH environment variable.

The essence of the PATH environment variable is as follows:

1. The PATH variable is assigned a value that consists of a list of folders, that is, paths in the system.

2. When you run a file on the command line, the operating system tries to find it both in the current folder (where you went with the “cd” command, or open by default), and in each folder specified in the PATH environment variable

3. If the file is found in the current folder, or in any PATH folder, then it is launched.

This is the reason the following command always works:

find /?

The reason is that it is placed in one of the folders listed in PATH (namely C:\Windows\System32\).

To view the current value of the PATH environment variable, run any of the following commands:

Get-ChildItem -Path Env:PATH

$env:PATH

Example PATH content in Windows 11:

C:\Program Files\PowerShell\7-preview;C:\Program Files\ImageMagick-7.1.0-Q16-HDRI;C:\Server\bin\PHP\;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\libnvvp;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\Nsight Compute 2022.1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\PowerShell\7-preview\preview;C:\Users\MiAl\AppData\Local\Microsoft\WindowsApps

You can place frequently used utilities in a folder included in PATH. Either you can add a new folder to PATH with the utilities you want to run without specifying the full paths to the executable files, or without having to change to the directory with these utilities.

You can set the value of PATH (and other environment variables) both in the GUI and on the command line.

See also:

Do I need to specify the extension of the executable file

When running executable files, it is not necessary to specify the extension, because the console will understand what you mean. For example, the following two commands are identical:

hashcat.exe

hashcat

Conclusion

This note is intended to give you a general idea of how to start and use the command line utilities. For basic information on using a particular utility, see the help displayed with the -h option or the program's documentation.

If you encounter an error when starting the utility, try running the program in an elevated command prompt (with admin rights).

If you get a message that “file not found”, go to the folder with the installed program using the “cd” command, or drag and drop the executable file to the command line.

If you received an error message inside the program when starting the program, then study the utility options and examples of its launch in more detail.

How to check PowerShell version in Windows 11

Finding your version of PowerShell will help you find out which PowerShell features you have access to. The PowerShell command lets you specify a version number, and we'll show you how.

How to find out the installed version of PowerShell

There is a PowerShell utility to find the version number, which is what we are going to use.

First, press Win+x and select “Windows Terminal”:

In the Windows Terminal window that opens, enter the following command and press Enter:

$PSVersionTable

PowerShell displays various numbers. Here, the first value "PSVersion" is your version of PowerShell.

You can now close the PowerShell window.

How to install the latest version of PowerShell

By default, all versions of Windows, even the latest Windows 11, provided with PowerShell 5, although the current version is PowerShell 7. To install it, see “How to install the latest PowerShell on Windows 11”.

How to check the built-in PowerShell version

If you installed PowerShell 6 or 7, you now have two versions at the same time on your system: PowerShell 5 and the latest. Windows Terminal can use any of these versions by default.

To find out your built-in PowerShell version, open the Start menu, search for “Windows PowerShell”, and click it in the search results.

In the PowerShell window that opens, enter the following command and press Enter:

$PSVersionTable

Or, no matter how you opened the command line, you can find out the versions with the following command sequences.

To check the built-in PowerShell version:

powershell
$PSVersionTable

To find out the version of PowerShell installed:

pwsh
$PSVersionTable

If the “pwsh” command is not found, then try “pwsh-preview”.

How to update the built-in version of PowerShell

Windows 10 updates the built-in PowerShell tool when installing system updates. This means that you should regularly update your computer to always use the latest version of PowerShell.

How to install the latest PowerShell on Windows 11

What's new in PowerShell 7

PowerShell 5.1 is installed by default in Windows 10 and Windows 11. In recent years, there has been an active development of new versions of PowerShell 7.*: 7.0, 7.1. PowerShell 7.2 beta is currently in development

You can view the PowerShell 6.* and PowerShell 7.* changelog on this page: https://github.com/PowerShell/PowerShell/tree/master/CHANGELOG

Despite the rapid development of the seventh version of PowerShell, the fifth version of PowerShell is still installed by default in the Windows operating system. Even the latest Windows 11 has PowerShell 5 installed.

PowerShell 7 is available for Windows, macOS, and Linux. We will show you how to install it on Windows 11.

Please note that PowerShell 7 is not currently a replacement for PowerShell 5, which means that when PowerShell 7 is installed, the fifth version will still be available on the system.

There are frequent updates for PowerShell 7, you can update to the latest versions of PowerShell 7 in the same ways that are shown in this article.

The latest version of PowerShell 7 can be downloaded in two ways - go to the releases page and find the PowerShell 7 installer; or use the script to download PowerShell 7 right in the command line.

Where to download PowerShell 7 (official site)

The first method we'll look at uses an .msi file to install PowerShell. MSI packages work almost identically to an EXE file and allow you to install a program using a graphical user interface. This is an installation method that only uses the required and key files. All you need to do is double click on the file to launch the installation wizard.

To download the package, launch your browser and go to the PowerShell Github Releases page. Scroll down to the Assets section and find the MSI file (PowerShell-*-win-x64.msi) there to download it.

Be sure to select the correct package for your version of Windows, x64 for 64-bit or x86 for 32-bit systems.

When prompted, select a download location and click Save to start downloading.

Once the download is complete, navigate to the folder where the file is located and double-click it to start the installation.

How to download PowerShell 7 from the command line

The PowerShell developers have also created a script that can be called directly from PowerShell. It is a one-line cmdlet that automatically downloads and runs the installation wizard. All you need to do is paste in the code snippet and hit the Enter key.

Start PowerShell and copy/paste the following cmdlet into the window:

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

Press Enter and PowerShell will run the command and start downloading.

If you are curious about what exactly the above command does, then the following notation may help you figure it out:

Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI"

That is, at the first stage, the command downloads the file https://aka.ms/install-powershell.ps1 and then runs it.

PowerShell 7 Installer

When the installation wizard opens, click Next to install PowerShell 7.

On the next screen, select the folder where the PowerShell 7 files will be located and click Next:

Then you decide which additional features to include during installation. You can enable or disable the following five options:

  • Add PowerShell to Path Environment Variable: Adds PowerShell to the Windows Path environment variable and allows PowerShell to be invoked from any other shell or terminal.
  • Register Windows Event Logging Manifest: Adds PowerShell to the Windows Event Registration manifest and allows events to be logged from a PowerShell instance.
  • Enable PowerShell remoting: Enables the ability to remotely run commands on this system.
  • Add ‘Open here’ context menus to Explorer: Adds an option to the right-click context menu that opens a PowerShell instance in the folder you clicked.
  • Add ‘Run with PowerShell 7-preview’ context menus for PowerShell files: Adds an option to the right-click context menu that prompts PowerShell files to run a script using PowerShell 7.

Click “Next” after selecting all the additional features you want.

On this window, you can choose if you want PowerShell to be updated using Windows Update. You can still update PowerShell either manually or along with Windows updates.

Click “Next” after choosing the update options.

Click “Intall” to start installation. A UAC prompt will appear asking for administrator rights to install the package. Click “Yes” to continue.

When the installation wizard completes, click Finish to exit.

How to open PowerShell 7

Once the installation is complete, you can open PowerShell 7 in several ways.

If you selected the Add PowerShell to Path Environment Variable and Add ‘Open here’ Context Menus to Explorer options, you can enter

pwsh

or right-click any folder and select PowerShell 7 → Open here.

However, one of the easiest ways is to search for “pwsh”. Then press Enter or click on the PowerShell icon with the mouse. Here you can also run PowerShell 7 with Administrator rights.

To make sure you are using PowerShell 7, take a look at the window title:

To update the help, run the command:

Update-Help

If the previous command failed, then try updating the help like this:

Update-Help -UICulture en-US

How to make Terminal use PowerShell 7 by default

The default command line in Windows 11 is Terminal.

Terminal is a pretty and functional program, but even after installing PowerShell 7, it uses PowerShell 5 by default. This can be easily changed.

To do this, press Win+x and select “Windows Terminal”:

Click on the down arrow button to the right of the window names and select “Settings” from the menu:

In the drop-down menu “Default profile” select “PowerShell”, then click “Save”:

Terminal will now use the most recently installed version of Terminal by default.

If you want to switch to PowerShell 5, then enter at the command line:

powershell

Alternatively, select the appropriate option when opening a new tab:

How to manage services on Windows

What are services

Services are a kind of programs that run in the background and do not require user input.

Services can either be specific to the Windows operating system or be third-party applications. Examples of services that the user can install himself: web server, VNC remote desktop server, SSH server, MySQL server.

You can manage services:

  • in the graphical interface
  • in command line
  • in PowerShell

Configuring services in the GUI

To open the service manager, search for “Services” and press Enter:

Another way to open this window is to press Win+r and enter:

services.msc

Here, in the Name column, you will see a list of the services running on your system, along with their Description. You will also be able to see their Status – whether they are running or stopped, as well as Startup Type and Log On As.

Windows service startup types

Windows 10 offers the following startup types:

  • Automatic
  • Automatic (Delayed Start)
  • Manual
  • Manual (Trigger Start)
  • Disabled

Start, stop, disable Windows services

To start, stop, pause, resume, or restart any Windows service, select the service and right-click it. You will be presented with these options.

If you want to manage additional options, double-click the Service to open its properties window.

Here, in the Startup Type drop-down menu, you will be able to select the startup type for the Service.

In the Service Status section, you will see the Start, Stop, Pause, Resume buttons.

In the Properties window, you will also see other tabs, such as Log On, Recovery, and Dependencies, which offer additional options and information.

After making the changes, you will need to click “Apply” button.

Managing Services Using the Command Line

You can also use command prompt to start, stop, pause, resume service. To use the console, open a Command Prompt or PowerShell with administrator rights and run one of the following commands.

To start the service:

net start SERVICE

For example, to start the mysql service:

net start mysql

To stop the service:

net stop SERVICE

For example, to stop the mysql service:

net stop mysql

To pause a service (not all services can be paused!):

net pause SERVICE

To resume the service:

net continue SERVICE

To disable autostart of a service:

sc config "SERVICE_NAME" start=disabled

For example, to disable subsequent starts of the mysql service:

sc config "mysql" start=disabled

To enable autostart of the service:

sc config "SERVICE_NAME" start=auto

For example, to enable autostart of the mysql service:

sc config "mysql" start=auto

Enumerating the states of active services and drivers

sc query

Enumerating Win32 Services Only

sc query type=service

To view the status of a specific service:

sc query SERVICE_NAME

For example, to see the status of an Apache2.4 service:

sc query Apache2.4

Managing Windows Services with PowerShell

PowerShell is Microsoft's task automation and configuration management framework. In this section, we will walk you through how to manage Windows services through PowerShell, as it is much faster and more efficient than other methods.

As you probably know, one of the most important parts of every operating system is the service that runs through it, and in general, it can be said that every part of the operating system that starts has a specific service that can be controlled and monitored.

Here's a comprehensive guide to using PowerShell to manage Windows services.

Launch PowerShell Terminal as Administrator. To do this, press Win+x and select Windows PowerShell (Admin):

First, you should get a list of available services using the following command:

Get-Service

This is the sample output you will receive.

In the default output, you will see 3 main sections: Status, Name and DisplayName. Now, if you want to find and list a specific service, you can filter out any of the parameters.

Examples

Show all services with names starting with wi:

Get-Service -Name wi*

Show all services whose display names start with win:

Get-Service -DisplayName win*

Note: if you want to access another computer over the network, you can view the list of services for that system using this command:

Get-Service -ComputerName SERVER1

An important part of service management is the management of dependent services.

To access the list of DependentServices for a specific service, we can use the following command:

Get-Service -Name SERVICE_NAME -DependentServices

For example:

Get-Service -Name WSearch -DependentServices

You can also use the RequiredServices parameter to get a list of service prerequisites.

Get-Service -Name SERVICE_NAME -RequiredServices

For example:

Get-Service -Name WSearch -RequiredServices

So with the commands above, we can find the name of the service you want, see the status and associated services or their dependencies. Now let's look at the commands for managing services.

To stop the service using PowerShell, you can use the following command:

Stop-Service -Name SERVICE_NAME

For example:

Stop-Service -Name Apache2.4

The following examples will be shown on the Apache2.4 service. That is, in the following commands, replace “Apache2.4” with the name of the service you are interested in.

To start a service in PowerShell, you can use this command:

Start-Service -Name Apache2.4

One of the most commonly used commands for working with services is the restart service command. The structure of the service restart command is as follows:

Restart-Service -Name Apache2.4

Finally, the following command is used to temporarily suspend a service.

Suspend-Service -Name Apache2.4

To change the startup mode of the service, use a command of the form:

Set-Service -Name SERVICE_NAME -StartupType START_TYPE

The START_TYPE can be:

  • Automatic – the service will be started or was started by the operating system at system startup. If an auto-start service depends on a manually-started service, the manually-started service also starts automatically at system startup.
  • AutomaticDelayedStart – Runs shortly after the system boots.
  • Disabled – the service is disabled and cannot be started by the user or application.
  • InvalidValue – Has no effect. The cmdlet does not return an error, but the StartupType of the service is not changed.
  • Manual – the service is started only manually, by the user, using the service control manager or application.

These are the most commonly used commands for managing services in PowerShell. For more information on PowerShell commands and how they work, use the Get-Help command.

For example:

Get-Help *-Service
Get-Help New-Service

How to display all environment variables at the Windows command prompt

This article will show you how to display all environment variables from the Windows command line.

PowerShell and CMD

First of all, you need to distinguish what kind of program you are working in. The first appeared CMD - Windows command line, shell. For many years, CMD was the only option for running on the Windows command line.

Then PowerShell came along. In the beginning, it was an environment that could be specially launched. In recent years, PowerShell has become more common, in the “Power User Menu”, which is invoked by the Win+x keyboard shortcut, PowerShell has replaced CMD. Also, the new Terminal uses PowerShell by default.

The commands for displaying all environment variables depend on whether you are in PowerShell or CMD, so you need to differentiate between them.

PowerShell looks like this:

Or like this:

That is, the command line prompt begins with “PS”.

And the CMD looks like this:

Or like this:

How to list all environment variables in PowerShell

In PowerShell, use one of the following commands:

gci env:
ls env:
dir env:

They are not only equivalent, in fact, they are just aliases for the same command. That is, there is no difference in their use.

How to display all environment variables in CMD

To display environment variables in CMD use the command:

SET

To cut the output in one screen with the ability to scroll through the list, use the following construction:

SET | more

To save the output to a file:

SET > output.txt

This text file, output.txt, can be opened in any editor such as Notepad.

To display the value of a specific variable, use the familiar set command with the variable name:

set VARIABLE

For instance:

set PATH

The set command prints the value of all variables that start with the line VARIABLE. For example, the previous command will print the values of the PATH and PATHEXT variables.

And the following command will print the values of all variables whose name begins with P:

set P

Note that command names on Windows are not case sensitive.

Loading...
X