- Find windows OS version from command line
- Find OS Version and Service Pack number from CMD
- Check Windows version using WMIC command
- FindFirstFileExA function (fileapi.h)
- Syntax
- Parameters
- Return value
- Remarks
- Examples
- How to Find the Windows version, build and edition from ISO or DVD
- Find Windows version, build, edition from ISO file
- DISM Get-WimInfo showing the wrong version?
- FindFirstFileExW function (fileapi.h)
- Syntax
- Parameters
- Return value
- Remarks
- Examples
Find windows OS version from command line
Windows has command line utilities that show us the version of the Windows OS running on the computer, including the service pack number. There are multiple CMD commands that help with finding this, you can pick the one that suits your need. Ver command can show you the OS version whereas Systeminfo command can additionally give you service pack, OS edition and build number etc.
Find OS Version and Service Pack number from CMD
As you can see above, ver command shows only OS version but not the service pack number. We can find service pack number as well with Systeminfo command. Systeminfo dumps lot of other information too, which we can filter out using findstr command.
This command works on XP, Vista and Windows 7 and on Server editions also. Find below example for Win7.
In case of Windows 7 SP1, the output would be slightly different as below.
If you want to print more details, then you can use just ‘OS’ in the findstr search pattern. See example below for Server 2008.
Check Windows version using WMIC command
Run the below WMIC command to get OS version and the service pack number.
Example on Windows 7:
If you want to find just the OS version, you can use ver command. Open command window and execute ver command. But note that this does not show service pack version.
This command does not show version on a Windows 7 system.
FindFirstFileExA function (fileapi.h)
Searches a directory for a file or subdirectory with a name and attributes that match those specified.
For the most basic version of this function, see FindFirstFile.
To perform this operation as a transacted operation, use the FindFirstFileTransacted function.
Syntax
Parameters
The directory or path, and the file name. The file name can include wildcard characters, for example, an asterisk (*) or a question mark (?).
This parameter should not be NULL, an invalid string (for example, an empty string or a string that is missing the terminating null character), or end in a trailing backslash (\).
If the string ends with a wildcard, period, or directory name, the user must have access to the root and all subdirectories on the path.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to approximately 32,000 wide characters, call the Unicode version of the function (FindFirstFileExW), and prepend «\\?\» to the path. For more information, see Naming a File.
The information level of the returned data.
This parameter is one of the FINDEX_INFO_LEVELS enumeration values.
A pointer to the buffer that receives the file data.
The pointer type is determined by the level of information that is specified in the fInfoLevelId parameter.
The type of filtering to perform that is different from wildcard matching.
This parameter is one of the FINDEX_SEARCH_OPS enumeration values.
A pointer to the search criteria if the specified fSearchOp needs structured search information.
At this time, none of the supported fSearchOp values require extended search information. Therefore, this pointer must be NULL.
Specifies additional flags that control the search.
Value | Meaning |
---|---|
FIND_FIRST_EX_CASE_SENSITIVE 1 | Searches are case-sensitive. |
FIND_FIRST_EX_LARGE_FETCH 2 | Uses a larger buffer for directory queries, which can increase performance of the find operation. Windows ServerВ 2008, WindowsВ Vista, Windows ServerВ 2003 and WindowsВ XP:В В This value is not supported until Windows ServerВ 2008В R2 and WindowsВ 7. |
FIND_FIRST_EX_ON_DISK_ENTRIES_ONLY 4 | Limits the results to files that are physically on disk. This flag is only relevant when a file virtualization filter is present. |
Return value
If the function succeeds, the return value is a search handle used in a subsequent call to FindNextFile or FindClose, and the lpFindFileData parameter contains information about the first file or directory found.
If the function fails or fails to locate files from the search string in the lpFileName parameter, the return value is INVALID_HANDLE_VALUE and the contents of lpFindFileData are indeterminate. To get extended error information, call the GetLastError function.
Remarks
The FindFirstFileEx function opens a search handle and returns information about the first file that the file system finds with a name that matches the specified pattern. This may or may not be the first file or directory that appears in a directory-listing application (such as the dir command) when given the same file name string pattern. This is because FindFirstFileEx does no sorting of the search results. For additional information, see FindNextFile.
The following list identifies some other search characteristics:
- The search is performed strictly on the name of the file, not on any attributes such as a date or a file type.
- The search includes the long and short file names.
- An attempt to open a search with a trailing backslash always fails.
- Passing an invalid string, NULL, or empty string for the lpFileName parameter is not a valid use of this function. Results in this case are undefined.
After the search handle is established, use it in the FindNextFile function to search for other files that match the same pattern with the same filtering that is being performed. When the search handle is not needed, it should be closed by using the FindClose function.
As stated previously, you cannot use a trailing backslash (\) in the lpFileName input string for FindFirstFileEx, therefore it may not be obvious how to search root directories. If you want to see files or get the attributes of a root directory, the following options would apply:
- To examine files in a root directory, you can use «C:\*» and step through the directory by using FindNextFile.
- To get the attributes of a root directory, use the GetFileAttributes function.
To examine a directory that is not a root directory, use the path to that directory, without a trailing backslash. For example, an argument of «C:\Windows» returns information about the directory «C:\Windows», not about a directory or file in «C:\Windows». To examine the files and directories in «C:\Windows», use an lpFileName of «C:\Windows*».
The following call:
Is equivalent to the following call:
Be aware that some other thread or process could create or delete a file with this name between the time you query for the result and the time you act on the information. If this is a potential concern for your application, one possible solution is to use the CreateFile function with CREATE_NEW (which fails if the file exists) or OPEN_EXISTING (which fails if the file does not exist).
If you are writing a 32-bit application to list all the files in a directory and the application may be run on a 64-bit computer, you should call Wow64DisableWow64FsRedirection before calling FindFirstFileEx and call Wow64RevertWow64FsRedirection after the last call to FindNextFile. For more information, see File System Redirector.
If the path points to a symbolic link, the WIN32_FIND_DATA buffer contains information about the symbolic link, not the target.
In WindowsВ 8 and Windows ServerВ 2012, this function is supported by the following technologies.
Technology | Supported |
---|---|
Server Message Block (SMB) 3.0 protocol | Yes |
SMB 3.0 Transparent Failover (TFO) | Yes |
SMB 3.0 with Scale-out File Shares (SO) | Yes |
Cluster Shared Volume File System (CsvFS) | Yes |
Resilient File System (ReFS) | Yes |
В
Examples
The following code shows a minimal use of FindFirstFileEx. This program is equivalent to the example in the FindFirstFile topic.
The fileapi.h header defines FindFirstFileEx as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
How to Find the Windows version, build and edition from ISO or DVD
Windows 10 ISO files downloaded from Microsoft will have descriptive names, such as en_windows_10_pro_10586_x64_dvd.iso and en_windows_10_pro_14393_x86_dvd.iso , depending upon the variant you downloaded. The file name depicts the language, version, build edition and the bitness of the Operating System contained in the ISO.
Let’s assume you have a copy of the Windows ISO with a generic name such as windows_10.iso (which doesn’t make any sense) obtained from a friend. To find the Windows version, build and edition from an ISO file or Windows Setup DVD, you can use the DISM tool.
Find Windows version, build, edition from ISO file
To find the Windows version, build and edition from an ISO file or DVD, use these steps:
- Mount the ISO file by double clicking on it. By default, Mount will be the default action for ISO files. If not, right-click on the file and choose “Mount” in the context menu.
- Double-click the drive letter of the mounted drive.
- Double-click the Sources folder.
- Sort folder contents by Name, and look for a file named install.wim . If install.wim is missing, then you’ll have install.esd .
Install.esd located in the Sources folder.
Open an elevated Command Prompt window, and then type the following command:
In the ISO file, if you have install.esd instead of install.wim , you’d type:
DISM can handle both these file formats ( .wim & .esd ), at least in Windows 10.
Running DISM command on install.esd
You’ll see the following output:
If you’re using Windows 7, running the above DISM command-line with the .esd file name parameter would throw the following error:
In that case, you can pass boot.wim as the parameter, as below: Running DISM command on boot.wim
Which results in the following output:
Note that for Multi-arch ISO files that include both 32-bit and 64-bit versions of Windows, the boot.wim, install.wim, install.esd file path varies slightly. These files are located under their respective architecture folders.
That’s it! You’ve now obtained the maximum information about the Operating System included in an ISO file, such as the OS version, edition, Service Pack level, architecture.
DISM Get-WimInfo showing the wrong version?
Sometimes, the Windows 8 or 10 ISOs may have the wrong version info (header?) causing the above DISM command to show the wrong version or build.
I downloaded the Windows 20 20H2 ISO (20H2 Build starts with 19042.nnn) from Microsoft.
- Filename: Win10_20H2_English_x64.iso
- SHA-256: e793f3c94d075b1aa710ec8d462cee77fde82caf400d143d68036f72c12d9a7e
Running DISM showed this:
Whereas, 20H2 build starts with 19042.nnn (as shown by the winver command)
The setup.exe (inside the 20H1 ISO) file’s version showed up as 19041.xxx, instead of 19042.nnn. So, it’s a glitch in this particular ISO.
So, be aware of the above issues. The above can happen sometimes.
FindFirstFileExW function (fileapi.h)
Searches a directory for a file or subdirectory with a name and attributes that match those specified.
For the most basic version of this function, see FindFirstFile.
To perform this operation as a transacted operation, use the FindFirstFileTransacted function.
Syntax
Parameters
The directory or path, and the file name. The file name can include wildcard characters, for example, an asterisk (*) or a question mark (?).
This parameter should not be NULL, an invalid string (for example, an empty string or a string that is missing the terminating null character), or end in a trailing backslash (\).
If the string ends with a wildcard, period, or directory name, the user must have access to the root and all subdirectories on the path.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to approximately 32,000 wide characters, call the Unicode version of the function (FindFirstFileExW), and prepend «\\?\» to the path. For more information, see Naming a File.
The information level of the returned data.
This parameter is one of the FINDEX_INFO_LEVELS enumeration values.
A pointer to the buffer that receives the file data.
The pointer type is determined by the level of information that is specified in the fInfoLevelId parameter.
The type of filtering to perform that is different from wildcard matching.
This parameter is one of the FINDEX_SEARCH_OPS enumeration values.
A pointer to the search criteria if the specified fSearchOp needs structured search information.
At this time, none of the supported fSearchOp values require extended search information. Therefore, this pointer must be NULL.
Specifies additional flags that control the search.
Value | Meaning |
---|---|
FIND_FIRST_EX_CASE_SENSITIVE 1 | Searches are case-sensitive. |
FIND_FIRST_EX_LARGE_FETCH 2 | Uses a larger buffer for directory queries, which can increase performance of the find operation. Windows ServerВ 2008, WindowsВ Vista, Windows ServerВ 2003 and WindowsВ XP:В В This value is not supported until Windows ServerВ 2008В R2 and WindowsВ 7. |
FIND_FIRST_EX_ON_DISK_ENTRIES_ONLY 4 | Limits the results to files that are physically on disk. This flag is only relevant when a file virtualization filter is present. |
Return value
If the function succeeds, the return value is a search handle used in a subsequent call to FindNextFile or FindClose, and the lpFindFileData parameter contains information about the first file or directory found.
If the function fails or fails to locate files from the search string in the lpFileName parameter, the return value is INVALID_HANDLE_VALUE and the contents of lpFindFileData are indeterminate. To get extended error information, call the GetLastError function.
Remarks
The FindFirstFileEx function opens a search handle and returns information about the first file that the file system finds with a name that matches the specified pattern. This may or may not be the first file or directory that appears in a directory-listing application (such as the dir command) when given the same file name string pattern. This is because FindFirstFileEx does no sorting of the search results. For additional information, see FindNextFile.
The following list identifies some other search characteristics:
- The search is performed strictly on the name of the file, not on any attributes such as a date or a file type.
- The search includes the long and short file names.
- An attempt to open a search with a trailing backslash always fails.
- Passing an invalid string, NULL, or empty string for the lpFileName parameter is not a valid use of this function. Results in this case are undefined.
After the search handle is established, use it in the FindNextFile function to search for other files that match the same pattern with the same filtering that is being performed. When the search handle is not needed, it should be closed by using the FindClose function.
As stated previously, you cannot use a trailing backslash (\) in the lpFileName input string for FindFirstFileEx, therefore it may not be obvious how to search root directories. If you want to see files or get the attributes of a root directory, the following options would apply:
- To examine files in a root directory, you can use «C:\*» and step through the directory by using FindNextFile.
- To get the attributes of a root directory, use the GetFileAttributes function.
To examine a directory that is not a root directory, use the path to that directory, without a trailing backslash. For example, an argument of «C:\Windows» returns information about the directory «C:\Windows», not about a directory or file in «C:\Windows». To examine the files and directories in «C:\Windows», use an lpFileName of «C:\Windows*».
The following call:
Is equivalent to the following call:
Be aware that some other thread or process could create or delete a file with this name between the time you query for the result and the time you act on the information. If this is a potential concern for your application, one possible solution is to use the CreateFile function with CREATE_NEW (which fails if the file exists) or OPEN_EXISTING (which fails if the file does not exist).
If you are writing a 32-bit application to list all the files in a directory and the application may be run on a 64-bit computer, you should call Wow64DisableWow64FsRedirection before calling FindFirstFileEx and call Wow64RevertWow64FsRedirection after the last call to FindNextFile. For more information, see File System Redirector.
If the path points to a symbolic link, the WIN32_FIND_DATA buffer contains information about the symbolic link, not the target.
In WindowsВ 8 and Windows ServerВ 2012, this function is supported by the following technologies.
Technology | Supported |
---|---|
Server Message Block (SMB) 3.0 protocol | Yes |
SMB 3.0 Transparent Failover (TFO) | Yes |
SMB 3.0 with Scale-out File Shares (SO) | Yes |
Cluster Shared Volume File System (CsvFS) | Yes |
Resilient File System (ReFS) | Yes |
В
Examples
The following code shows a minimal use of FindFirstFileEx. This program is equivalent to the example in the FindFirstFile topic.
The fileapi.h header defines FindFirstFileEx as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.