从非特权用户命令行找出 Windows 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8389312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find out windows version from non-privileged user command line
提问by Jared
I need a way to find out what version of windows I'm running in using simple command line tools (no powershell). I need it to work from a non-privileged user, and I need to be able to parse out the difference between Windows XP, Vista, server 2008, and 7. I'm currently using:
wmic os get Caption
but that fails when the user doesn't have permissions to run wmic.
我需要一种方法来使用简单的命令行工具(没有 powershell)找出我正在运行的 Windows 版本。我需要它从非特权用户那里工作,并且我需要能够解析出 Windows XP、Vista、服务器 2008 和 7 之间的差异。我目前正在使用:
wmic os get Caption
但是当用户没有有权限运行 wmic。
Update:To clarify, I need this command to not break with different service pack levels, etc. which probably rules out parsing a specific version number. Also if you look at this listof windows versions, you'll see that the numbers reported on Windows 7 and server 2008 r2 are the same.
更新:澄清一下,我需要此命令不会因不同的服务包级别等而中断,这可能会排除解析特定版本号的可能性。此外,如果您查看此Windows 版本列表,您会发现 Windows 7 和 server 2008 r2 上报告的数字相同。
回答by Jared
I solved this problem by parsing the output of:
我通过解析以下输出解决了这个问题:
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "ProductName"
回答by Sriniv
systeminfo command shows everything about the os version including service pack number and the edition you are using.
systeminfo 命令显示有关操作系统版本的所有信息,包括服务包编号和您使用的版本。
C:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft Windows 7 Enterprise
OS Version: 6.1.7601 Service Pack 1 Build 7601
Reference: Find Windows version from command prompt
回答by Caleb Jares
You can use ver
. I'm on a school computer with a non-privileged command prompt, and it gives me Microsft Windows [Version 6.1.7601]
. I'm sure you'd be able to sort out Vista and XP from the number you get.
您可以使用ver
. 我在一台带有非特权命令提示符的学校计算机上,它给了我Microsft Windows [Version 6.1.7601]
. 我相信你能从你得到的数字中分辨出 Vista 和 XP。
回答by Joey
cmd
displays the Windows version when started:
cmd
启动时显示 Windows 版本:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Joey>_
This is also a similar line as the one ver
spits out, indeed.
ver
确实,这也是一条与吐出的相似的线。
One option then might be
一种选择可能是
echo exit|cmd|findstr Windows
another
其他
cmd /c ver
depending on whether you have a pipeline or not.
取决于您是否有管道。
回答by Nior aon Duine
if not CMDEXTVERSION 2 (
echo Error: This batch requires Command Extensions version 2 or higher
exit /b 1
)
FOR /F "usebackq tokens=4 delims=] " %%I IN (`ver`) DO for /F "tokens=1,2 delims=." %%J IN ("%%I") do set WindowsVersion=%%J.%%K
if "%WindowsVersion%" LSS "6.1" (
echo Error: This batch requires Windows 7 SP1 or higher
exit /b 1
)
回答by user5419367
You can get the SysInternals and install onto your C:\ directory. After that you can then go to a command prompt and use the command PSINFO.
您可以获取 SysInternals 并安装到您的 C:\ 目录中。之后,您可以转到命令提示符并使用命令 PSINFO。
It is great because it lets me query any PC on the network (that I have access to). At the command prompt you type: PSINFO \exactnameofcomputer
这很棒,因为它让我可以查询网络上的任何 PC(我可以访问)。在命令提示符下键入: PSINFO \exactnameofcomputer
(PSINFO whack whack exactnameofcomputer)
(PSINFO 重击计算机的确切名称)
Then hit enter. It will take a moment or two to report back, depending on where that computer is located at.
然后按回车。返回报告需要一两分钟,具体取决于该计算机所在的位置。