- Windows commands
- Prerequisites
- Command shell overview
- Command-line reference A-Z
- How to extract CAB File using command line tools in Windows 10
- expand.exe
- makecab.exe
- extrac32
- Extract CAB File using command line
- How to extract .msi features from command line?
- 1 Answer 1
- How to extract a self extracting exe from commandline
- 4 Answers 4
- How can you zip or unzip from the script using ONLY Windows’ built-in capabilities?
- 16 Answers 16
- PowerShell 5.0
Windows commands
All supported versions of Windows (server and client) have a set of Win32 console commands built in.
This set of documentation describes the Windows Commands you can use to automate tasks by using scripts or scripting tools.
Prerequisites
The information that is contained in this topic applies to:
- Windows Server 2019
- Windows Server (Semi-Annual Channel)
- Windows Server 2016
- Windows Server 2012 R2
- Windows Server 2012
- Windows Server 2008 R2
- Windows Server 2008
- Windows 10
- Windows 8.1
Command shell overview
The Command shell was the first shell built into Windows to automate routine tasks, like user account management or nightly backups, with batch (.bat) files. With Windows Script Host you could run more sophisticated scripts in the Command shell. For more information, see cscript or wscript. You can perform operations more efficiently by using scripts than you can by using the user interface. Scripts accept all Commands that are available at the command line.
Windows has two command shells: The Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.
PowerShell was designed to extend the capabilities of the Command shell to run PowerShell commands called cmdlets. Cmdlets are similar to Windows Commands but provide a more extensible scripting language. You can run Windows Commands and PowerShell cmdlets in Powershell, but the Command shell can only run Windows Commands and not PowerShell cmdlets.
For the most robust, up-to-date Windows automation, we recommend using PowerShell instead of Windows Commands or Windows Script Host for Windows automation.
You can also download and install PowerShell Core, the open source version of PowerShell.
Incorrectly editing the registry may severely damage your system. Before making the following changes to the registry, you should back up any valued data on the computer.
To enable or disable file and directory name completion in the Command shell on a computer or user logon session, run regedit.exe and set the following reg_DWOrd value:
To set the reg_DWOrd value, use the hexadecimal value of a control character for a particular function (for example, 0 9 is Tab and 0 08 is Backspace). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.
Command-line reference A-Z
To find information about a specific command, in the following A-Z menu, click the letter that the command starts with, and then click the command name.
How to extract CAB File using command line tools in Windows 10
In Windows environment, CAB refers to Cabinet files – an archive file format for Microsoft Windows. The format supports data compression and embedded digital certificates used for maintaining archive integrity. Using this file format, a user can store multiple files/folders into a single file with or without involving data compression in this archive.
Windows 10/8/7 can unzip or extract the contents of a compressed file as it is natively compatible with CAB files. Moreover, the OS can create, extract, or rebuild cab files. This means you do not require any additional third-party software for this task. All CAB files can be unzipped using basic Windows command line tools.
There are three built-in Windows command line tools for dealing with CAB files:
- expand.exe
- makecab.exe
- extrac32.exe
expand.exe
To see the command line option available for expand.exe, open a Command Prompt window, type the following and hit Enter:
makecab.exe
To see the command line option available for makecab.exe, open a Command Prompt window, type the following and hit Enter:
extrac32
To see the command line option available for extrac32, open a Command Prompt window, type the following and hit Enter:
Extract CAB File using command line
To extract the contents of Cab files, you can use any of the above tools. Let us take the example of expand.exe tool.
To extract the contents of a .cab file, first change the directory to point to the location of the source using the CD command and then run the following command:
Here you are extracting the contents of TWC.cab file into the C:\TWCFolder. -F is the number of files to expand. When you use ‘*’, it means all the files.
When completed, the tool will display the complete list of extracted files.
Close the command prompt windows and go to Windows Explorer. There, the complete list of full extracted file structure should be visible to you.
Incidentally, several free file compression software including 7-Zip, let you easily compress or extract the contents of a CAB file on a Windows system.
How to extract .msi features from command line?
I have an .msi that contains some development files (gstreamer development files) and I want to extract some features from .msi to some folder without installing from command line.
I know how to install some features using ADDLOCAL property of msiexec:
But when I’m trying to extract files without installing using administrative installation, it seems ADDLOCAL property doesn’t work and it extract all files in package:
Does somebody know how to extract only selected features from .msi without installing it into system?
1 Answer 1
Short Answer: Make a transform, set Feature Table => Level Column to 0 for features you want to exclude from file extract. Run administrative installation as follows:
Transform: There might be other ways that I can’t think of at the moment, but one way you can try is to make a transform that you apply to the administrative installation. Depending on the number of features in the MSI this could be a lot of work, or it might not be much work at all (if there are few features you want to exclude).
Feature Level: There is a peculiarity in an MSI whereby a feature that has its Feature level set to 0 will not be extracted during an administrative installation. This seems like a bug to me (it is by design though), but you can use it to achieve what you want here — I think — but it isn’t exactly pretty.
- Transform: Make a transform that sets the Level column in the Feature table to 0 for all the features you do not want to extract.
msiexec.exe: Apply the transform to the MSI via the command line as follows:
Tools: You need a tool to help you make this transform. You probably have this already, but for others: I recommend Orca.exe — Microsoft’s own SDK tool. However, there are a number of tools you can use that are free. The majority (I think) are described here: How can I compare the content of two (or more) MSI files? (scroll down to the list towards bottom — dark.exe is a decompiler and not an MSI viewer — the link describes comparing MSI files, not changing them).
Orca.exe will already be on disk (most likely) if you have Visual Studio installed. Try searching for Orca-x86_en-us.msi — under Program Files (x86) . Just install it and find Orca in the start menu (or search for it).
Advanced: There is a VBScript ( widiffdb.vbs ) linked in the above «compare MSI» answer. It allows comparison of two MSI files. There is another VBScript which allows you to update an MSI via SQL statements. See here: WiRunSQL.vbs. These scripts you can find on disk if you have the SDK installed, or you can find them on github.com. See sample use of the script towards the bottom in this answer. Try this if you have a massive amount of Feature levels to set to 0. Obviously set all features to 0 and then manually switch on the ones you need by setting them back to normal (1 or higher — depends on the MSI).
Mockup: Sample VBScript code to set all Feature levels to 0 :
Note! Do not run this on your main source MSI file. Make a copy!
No error handling in this script. To generate a transform see sample here (generate transform based on diff between original and modified MSI file).
How to extract a self extracting exe from commandline
Is there a way to extract a self extracting exe from commandline in windows?
I have a self extracting exe which is of type RAR. I want to extract the contents of this RAR only with the help of windows and not using any other tools (like 7zip, Unrar etc) which helps to extract. Also, I want to do it from the command line only.
Are there any utilities in windows which I can use to extract the self extracting exe file from commandline?
4 Answers 4
You might be able to get the self-extacting RAR archive to do what you want with one or more of the following RAR SFX (self-extracting archive) options:
GUI self-extracting modules support following command line switches:
I’m not sure if any of these options will suppress running a setup program that the SFX is configured to run.
Download UnRar for windows (freeware) from this link. It in itself is a self extracting archive, which when installed will give you the actual unrar.exe. You can then use unrar.exe to extract files from the command line.
Use unzip utility from http://www.info-zip.org/. It is an open source and binaries are available for all os flavors.
unzip command: unzip.exe sample.zip -d extract_folder
Download latest windows executable at ftp://ftp.info-zip.org/pub/infozip/win32/. After downloading the binary like ‘unz552xn-x64.exe’, run it in command line, it will give a set of files including unzip.exe. since unzip.exe does not have any dependency other files can be deleted.
For others that are looking for the answer to this.
Download the trial version or purchase WinRAR. Right click the files you want to package and select add to archive.
Check «create sfx archive» on the General tab, this will give you the file.exe
Select the «sfx options» on the Advanced tab, under the Modes tab select «hide all». If you don’t want the extracted files to show or stay after your program/script has run then «Unpack to temporary folder» under this same tab.
Under the Setup tab in the «run after extraction» put the program or script you would like to run.
Once file(s) have been packaged you will have a file called file.exe. (Note:File will be what you named the sfx archive). From command line type file.exe and it will extract to the temp location (if you selected that) and run the program/script that you specified. Once the program/script closes the folder in the temp location will be removed.
Notes:
If running from a WinPe CD or otherwise similar bootable media do not use «Unpack to Temporary Folder».
WinRAR only has to be on the computer making the sfx archive. Once the sfx archive is made you won’t need it to extract the files.
How can you zip or unzip from the script using ONLY Windows’ built-in capabilities?
In Windows you can zip some files by
right click → Send to → Compressed (zipped) folder
And unzip by double clicking on the .zip file and extract the files.
Is there a way to apply those abilities from a script (.bat file) without the need to install any third-party software?
16 Answers 16
Back in 2013, that was not possible. Microsoft didn’t provide any executable for this.
From Windows 8 on, .NET Framework 4.5 is installed by default, with System.IO.Compression.ZipArchive and PowerShell available, one can write scripts to achieve this, see https://stackoverflow.com/a/26843122/71312
To expand upon Steven Penny’s PowerShell solution, you can incorporate it into a batch file by calling powershell.exe like this:
As Ivan Shilo said, this won’t work with PowerShell 2, it requires PowerShell 3 or greater and .NET Framework 4.
If you have Java installed, you can compress to a ZIP archive using the jar command:
c = Creates a new archive file.
M = Specifies that a manifest file should not be added to the archive.
f = Indicates target file name.
PowerShell 5.0
Create result.zip from the entire Test folder:
Extract the content of result.zip in the specified Test folder:
It isn’t exactly a ZIP, but the only way to compress a file using Windows tools is:
Advanced example (from ss64.com):
Using 7-Zip:
Zip: you have a folder foo , and want to zip it to myzip.zip
Unzip: you want to unzip it ( myzip.zip ) to current directory ( ./ )
100 machines in production which don’t have 7zip on them. To install that I would have to get the DevOps install it on all those machines and on all new machines that will be added to the clusters. I would rather avoid it. – Roee Gavirel May 9 ’16 at 5:27
I’ve been looking to answer this exact question and from my research, DiryBoy’s response seems to be accurate.
I found the compact.exe program compresses files but not to create a highly compressed file (or set of files). It is similar to the option you get when right clicking on a drive letter or partition in Windows. You get the option to do cleanup (remove temp files, etc) as well as compress files. The compressed files are still accessible but are just compressed to create space on a drive that is low on space.
I also found compress.exe which I did happen to have on my computer. It isn’t natively on most windows machines and is part of the 2003 resource kit. It does make a zipped file of sorts but it is really more similar to files from a windows setup disk (has the underscore as the last character of the file extension or name). And the extract.exe command extracts those files.
However, the mantra is, if it can be done natively via the GUI then there is likely a way to do it via batch, .vbs, or some other type of script within the command line. Since windows has had the ‘send to’ option to create a zip file, I knew there had to be a way to do it via command line and I found some options.
Here is a great link that shows how to zip a file using windows native commands.
I tested it with a directory containing multiple nested files and folders and it worked perfectly. Just follow the format of the command line.
There is also a way to unzip the files via command line which I found as well. One way, just brings open an explorer window showing what the content of the zipped file is. Some of these also use Java which isn’t necessarily native to windows but is so common that it nearly seems so.