本文介绍了操作系统名称变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个脚本,在那里我能得到的Windows名称,并在该公司运行的所有计算机的系统版本,把它放在一个文本FIL。然后做一个系统变量从我的窗口的名字。我知道跑什么,但在那里我遇到的一个问题是一个占位符。所以这里是我的code:

I would like to run a script where I can get the windows Name and version of the system of all computers running in the company, put it in a text fil. Then make a system variable out of my windows name . I know what to run but where I am running into an issue is a place holder. so here is my code:

    :OS_NAME
    Set OS_NAME= systeminfo | find "OS Name"

    :OS_Ver
    Set OS_Version= systeminfo | findstr /B /C:"OS Version"

    systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /c:"BIOS Version" |  >> G:\Directory\%Computername%

    :OS_Arch
    IF exist "%programfiles(x86)% (SET OS_ARCH=X64)
    Else (SET OS_ARCH=X86)

    :Win_7
    systeminfo | find "Microsoft Windows 7" > nul
        if %ERRORLEVEL% == 0 (
            goto ver_7)


    :Ver_7
    Set Win7= systeminfo | find "Microsoft Windows 7"
    Echo %computername% is running %WIN7% in %OS_ARCH% Environment >> G:\Directory\Win7Comps.txt

所以基本上我想对于SYSTEMINFO的结果,我可以参考和解析它在我的SET命令时,我让我的系统变量的占位符。

So basically I would like a place holder for the results of Systeminfo which i can refer to and parse it my SET command when I am making my system variables.

谢谢,任何帮助将是AP preaciated。

Thanks, any help would be appreaciated.

推荐答案

不完全知道你在寻找什么,但我看到的最大的问题是,的SystemInfo 需要永远运行,并返回比你正在寻找更多的信息。你会更好使用 WMIC 捕捉WMI查询。这基本上是你的榜样脚本的改写,只是用 WMIC ,而不是的SystemInfo 。它应该是多,快多了。

Not exactly sure what you're looking for, but the biggest problem I see is that systeminfo takes forever to run and returns much more information than you're looking for. You'd be better off capturing wmi queries using wmic. This is basically a rewrite of your example script, just using wmic rather than systeminfo. It should be much, much faster.

@echo off
setlocal
set prefix=G:\Directory

for /f "usebackq tokens=1,2 delims==|" %%I in (`wmic os get name^,version /format:list`) do 2>NUL set "%%I=%%J"
for /f "tokens=2 delims==" %%I in ('wmic bios get version /format:list') do set "bios=%%I"
for /f "tokens=2 delims==" %%I in ('wmic computersystem get model /format:list') do set "model=%%I"

>>"%prefix%\%COMPUTERNAME%" echo OS Name: %name%
>>"%prefix%\%COMPUTERNAME%" echo OS Version: %version%
>>"%prefix%\%COMPUTERNAME%" echo PC Model: %model%
>>"%prefix%\%COMPUTERNAME%" echo BIOS Version: %bios%

if defined PROGRAMFILES(x86) (set arch=X64) else set arch=X86

if "%name%" neq "%name:Windows 8=%" (
    set out=%prefix%\Win8Comps.txt
) else if "%name%" neq "%name:Windows 7=%" (
    set out=%prefix%\Win7Comps.txt
) else if "%name%" neq "%name:Windows Vista=%" (
    set out=%prefix%\WinVistaComps.txt
) else if "%name%" neq "%name:Windows XP=%" (
    set out=%prefix%\WinXPComps.txt
)

>>"%out%" echo %COMPUTERNAME% is running %name% in %arch% environment

键入 WMIC /?有关详细信息,并尝试 WMIC COMPUTERSYSTEM GET /?或相似看到一个列表,可以每类下被查询的项目。

Type wmic /? for more info, and try wmic computersystem get /? or similar to see a list of items that can be queried under each class.

WMIC 是Windows的瑞士军刀。有趣的事实:你甚至可以用 WMIC 来在远程系统上安装软件的表。

wmic is the Swiss Army knife of Windows. Fun fact: you can even use wmic to generate a web page table of installed software on a remote system.

这篇关于操作系统名称变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 07:20