|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『楼 主』:
[已结]用批处理查看电脑硬件详细信息
使用 LLM 解释/回答一下
用批处理查看电脑硬件的详细信息
要求显示结果大致如下
硬盘型号。。。大小。。。
内存型号。。。大小。。。
显卡型号。。。大小。。。
主板型号。。。
cpu 型号。。。
。。。。。。。。。
。。。。。。。。。
等等。。。
反正是越详细越好,不知道批处理能不能做到呢?
如果批处理作不到,vbs也可以。
Last edited by HAT on 2008-10-21 at 12:21 ]
View detailed hardware information of the computer with batch processing
Requirement: Display the results roughly as follows
Hard disk model... size...
Memory model... size...
Graphics card model... size...
Motherboard model...
CPU model...
...
...
and so on...
In short, the more detailed the better. I wonder if batch processing can do it?
If batch processing can't do it, VBS is also okay.
Last edited by HAT on 2008-10-21 at 12:21 ]
|

致精致简! |
|
2007-11-25 01:50 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
利用WMIC可以获取到一些,比如硬盘的型号和大小:
wmic DiskDrive get Size,Model
其它的自己摸索一下吧。
还有某些三方工具也可以。
You can use WMIC to get some things, such as the model and size of the hard disk:
wmic DiskDrive get Size,Model
You can explore other things by yourself.
There are also some third-party tools available.
|
|
2007-11-25 03:07 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
具我所知WMIC都能查得出,本来想在网络日志(Blog)发一贴wmic应用类日志,只是我太懒了又怕那些英语单词
wmic查询硬盘
wmic path Win32_DiskDrive get index,interfacetype,model,size
devcon.exe查询硬盘
@echo off
setlocal enabledelayedexpansion
echo 硬盘型号 接口类型 修订版本
echo ======== ======== ========
for /f "tokens=1,2* delims=\" %%a in ('devcon.exe find gendisk^|find /v /i "USBSTOR\"^|find ":"') do call :fastslz "%%a" "%%b" "%%c"
echo.&pause
:fastslz
set "填充空格= "
set 类型=%~1%填充空格%
set 修订=%~2
set 修订=%修订:_= %
for %%i in (%修订%) do set 修订=%%i
for /f "tokens=1* delims=:" %%a in ('echo %3') do set 型号="%%~b"
set 型号=%型号:~0,30%
set 型号=%型号:"=%%填充空格%
set 型号=%型号:~1,30%
echo %型号%%类型:~0,12%%修订%
goto:eof
另外参考http://www.cn-dos.net/forum/viewthread.php?tid=35139&fpage=1
空了继续~~~~~~
As far as I know, WMIC can find out. Originally wanted to post a post about WMIC application logs on the network log (Blog), but I'm too lazy and afraid of those English words.
WMIC query hard disk
wmic path Win32_DiskDrive get index,interfacetype,model,size
devcon.exe query hard disk
@echo off
setlocal enabledelayedexpansion
echo Hard disk model Interface type Revision version
echo ======== ======== ========
for /f "tokens=1,2* delims=\" %%a in ('devcon.exe find gendisk^|find /v /i "USBSTOR\"^|find ":"') do call :fastslz "%%a" "%%b" "%%c"
echo.&pause
:fastslz
set "Fill spaces= "
set Type=%~1%Fill spaces%
set Revision=%~2
set Revision=%Revision:_= %
for %%i in (%Revision%) do set Revision=%%i
for /f "tokens=1* delims=:" %%a in ('echo %3') do set Model="%%~b"
set Model=%Model:~0,30%
set Model=%Model:"=%%Fill spaces%
set Model=%Model:~1,30%
echo %Model%%Type:~0,12%%Revision%
goto:eof
Also refer to http://www.cn-dos.net/forum/viewthread.php?tid=35139&fpage=1
Will continue later~~~~~~
|

第一高手 第二高手
我的小站
 |
|
2007-11-25 03:17 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
|
2007-11-25 03:21 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
wmic 确实强大,可惜不会英文,唉!
WMIC is indeed powerful, but it's a pity I don't know English, alas!
|

致精致简! |
|
2007-11-25 03:49 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by fastslz at 2007-11-25 03:21:
哈哈~lxmxn也没睡啊~
经常熬夜,人都憔悴了不少,惭愧……
Originally posted by fastslz at 2007-11-25 03:21:
Haha~ lxmxn isn't asleep either~
Staying up late frequently has made me look much more haggard. Ashamed...
|
|
2007-11-25 04:34 |
|
|
dato
高级用户
   
积分 916
发帖 377
注册 2004-3-8
状态 离线
|
|
2007-11-25 10:43 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
网上发现的
@echo off
color 0a
title 硬件检测
mode con cols=90
sc config winmgmt start= auto >nul 2<&1
net start winmgmt 2>1nul
setlocal ENABLEDELAYEDEXPANSION
echo 主版:
for /f "tokens=1,* delims==" %%a in ('wmic BASEBOARD get Manufacturer^,Product^,Version^,SerialNumber /value') do (
set /a tee+=1
if "!tee!" == "3" echo 制造商 = %%b
if "!tee!" == "4" echo 型 号 = %%b
if "!tee!" == "5" echo 序列号 = %%b
if "!tee!" == "6" echo 版 本 = %%b
)
set tee=0
echo BIOS:
for /f "tokens=1,* delims==" %%a in ('wmic bios get
CurrentLanguage^,Manufacturer^,SMBIOSBIOSVersion^,SMBIOSMajorVersion^,SMBIOSMinorVersion^,ReleaseDate /value') do (
set /a tee+=1
if "!tee!" == "3" echo 当前语言 = %%b
if "!tee!" == "4" echo 制造商 = %%b
if "!tee!" == "5" echo 发行日期 = %%b
if "!tee!" == "6" echo 版 本 = %%b
if "!tee!" == "7" echo SMBIOSMajorVersion = %%b
if "!tee!" == "8" echo SMBIOSMinorVersion = %%b
)
set tee=0
echo.
echo CPU:
for /f "tokens=1,* delims==" %%a in ('wmic cpu get name^,ExtClock^,CpuStatus^,Description /value') do (
set /a tee+=1
if "!tee!" == "3" echo CPU个数 = %%b
if "!tee!" == "4" echo 处理器版本 = %%b
if "!tee!" == "5" echo 外 频 = %%b
if "!tee!" == "6" echo 名称及主频率 = %%b
)
set tee=0
echo.
echo 显示器:
for /f "tokens=1,* delims==" %%a in ('wmic DESKTOPMONITOR get name^,ScreenWidth^,ScreenHeight^,PNPDeviceID /value') do (
set /a tee+=1
if "!tee!" == "3" echo 类 型 = %%b
if "!tee!" == "4" echo 其他信息 = %%b
if "!tee!" == "5" echo 屏幕高 = %%b
if "!tee!" == "6" echo 屏幕宽 = %%b
)
set tee=0
echo.
echo 硬 盘:
for /f "tokens=1,* delims==" %%a in ('wmic DISKDRIVE get model^,interfacetype^,size^,totalsectors^,partitions /value') do (
set /a tee+=1
if "!tee!" == "3" echo 接口类型 = %%b
if "!tee!" == "4" echo 硬盘型号 = %%b
if "!tee!" == "5" echo 分区数 = %%b
if "!tee!" == "6" echo 容 量 = %%b
if "!tee!" == "7" echo 总扇区 = %%b
)
echo 分区信息:
wmic LOGICALDISK where mediatype='12' get description,deviceid,filesystem,size,freespace
set tee=0
echo.
echo 网 卡:
for /f "tokens=1,* delims==" %%a in ('wmic NICCONFIG where "index='1'" get ipaddress^,macaddress^,description /value') do (
set /a tee+=1
if "!tee!" == "3" echo 网卡类型 = %%b
if "!tee!" == "4" echo 网卡IP = %%b
if "!tee!" == "5" echo 网卡MAC = %%b
)
set tee=0
echo.
echo 打印机:
for /f "tokens=1,* delims==" %%a in ('wmic PRINTER get caption /value') do (
set /a tee+=1
if "!tee!" == "3" echo 打印机名字 = %%b
)
set tee=0
echo.
echo 声 卡:
for /f "tokens=1,* delims==" %%a in ('wmic SOUNDDEV get name^,deviceid /value') do (
set /a tee+=1
if "!tee!" == "3" echo 其他信息 = %%b
if "!tee!" == "4" echo 型 号 = %%b
)
set tee=0
echo.
echo 内 存:
for /f "tokens=1,* delims==" %%a in ('systeminfo^|find "内存"') do (
echo %%a 4534 %%b
)
echo.
echo 显 卡:
del /f "%TEMP%\temp.txt" 2>nul
dxdiag /t %TEMP%\temp.txt
:显卡
rem 这里需要30秒左右!
if EXIST "%TEMP%\temp.txt" (
for /f "tokens=1,2,* delims=:" %%a in ('findstr /c:" Card name:" /c:"Display Memory:" /c:"Current Mode:" "%TEMP%\temp.txt"') do (
set /a tee+=1
if !tee! == 1 echo 显卡型号: %%b
if !tee! == 2 echo 显存大小: %%b
if !tee! == 3 echo 当前设置: %%b
) ) else (
ping /n 2 127.1>nul
goto 显卡
)
set /p var=需要额外信息吗(y/n):
if /i %var% == y notepad "%TEMP%\temp.txt"
del /f "%TEMP%\temp.txt" 2>nul
pause
Found online
@echo off
color 0a
title Hardware Detection
mode con cols=90
sc config winmgmt start= auto >nul 2<&1
net start winmgmt 2>1nul
setlocal ENABLEDELAYEDEXPANSION
echo Mainboard:
for /f "tokens=1,* delims==" %%a in ('wmic BASEBOARD get Manufacturer^,Product^,Version^,SerialNumber /value') do (
set /a tee+=1
if "!tee!" == "3" echo Manufacturer = %%b
if "!tee!" == "4" echo Model = %%b
if "!tee!" == "5" echo Serial Number = %%b
if "!tee!" == "6" echo Version = %%b
)
set tee=0
echo BIOS:
for /f "tokens=1,* delims==" %%a in ('wmic bios get
CurrentLanguage^,Manufacturer^,SMBIOSBIOSVersion^,SMBIOSMajorVersion^,SMBIOSMinorVersion^,ReleaseDate /value') do (
set /a tee+=1
if "!tee!" == "3" echo Current Language = %%b
if "!tee!" == "4" echo Manufacturer = %%b
if "!tee!" == "5" echo Release Date = %%b
if "!tee!" == "6" echo Version = %%b
if "!tee!" == "7" echo SMBIOSMajorVersion = %%b
if "!tee!" == "8" echo SMBIOSMinorVersion = %%b
)
set tee=0
echo.
echo CPU:
for /f "tokens=1,* delims==" %%a in ('wmic cpu get name^,ExtClock^,CpuStatus^,Description /value') do (
set /a tee+=1
if "!tee!" == "3" echo Number of CPUs = %%b
if "!tee!" == "4" echo Processor Version = %%b
if "!tee!" == "5" echo External Clock = %%b
if "!tee!" == "6" echo Name and Main Frequency = %%b
)
set tee=0
echo.
echo Monitor:
for /f "tokens=1,* delims==" %%a in ('wmic DESKTOPMONITOR get name^,ScreenWidth^,ScreenHeight^,PNPDeviceID /value') do (
set /a tee+=1
if "!tee!" == "3" echo Type = %%b
if "!tee!" == "4" echo Other Information = %%b
if "!tee!" == "5" echo Screen Height = %%b
if "!tee!" == "6" echo Screen Width = %%b
)
set tee=0
echo.
echo Hard Disk:
for /f "tokens=1,* delims==" %%a in ('wmic DISKDRIVE get model^,interfacetype^,size^,totalsectors^,partitions /value') do (
set /a tee+=1
if "!tee!" == "3" echo Interface Type = %%b
if "!tee!" == "4" echo Hard Disk Model = %%b
if "!tee!" == "5" echo Number of Partitions = %%b
if "!tee!" == "6" echo Capacity = %%b
if "!tee!" == "7" echo Total Sectors = %%b
)
echo Partition Information:
wmic LOGICALDISK where mediatype='12' get description,deviceid,filesystem,size,freespace
set tee=0
echo.
echo Network Card:
for /f "tokens=1,* delims==" %%a in ('wmic NICCONFIG where "index='1'" get ipaddress^,macaddress^,description /value') do (
set /a tee+=1
if "!tee!" == "3" echo Network Card Type = %%b
if "!tee!" == "4" echo Network Card IP = %%b
if "!tee!" == "5" echo Network Card MAC = %%b
)
set tee=0
echo.
echo Printer:
for /f "tokens=1,* delims==" %%a in ('wmic PRINTER get caption /value') do (
set /a tee+=1
if "!tee!" == "3" echo Printer Name = %%b
)
set tee=0
echo.
echo Sound Card:
for /f "tokens=1,* delims==" %%a in ('wmic SOUNDDEV get name^,deviceid /value') do (
set /a tee+=1
if "!tee!" == "3" echo Other Information = %%b
if "!tee!" == "4" echo Model = %%b
)
set tee=0
echo.
echo Memory:
for /f "tokens=1,* delims==" %%a in ('systeminfo^|find "Memory"') do (
echo %%a 4534 %%b
)
echo.
echo Graphics Card:
del /f "%TEMP%\temp.txt" 2>nul
dxdiag /t %TEMP%\temp.txt
:Graphics Card
rem It takes about 30 seconds here!
if EXIST "%TEMP%\temp.txt" (
for /f "tokens=1,2,* delims=:" %%a in ('findstr /c:" Card name:" /c:"Display Memory:" /c:"Current Mode:" "%TEMP%\temp.txt"') do (
set /a tee+=1
if !tee! == 1 echo Graphics Card Model: %%b
if !tee! == 2 echo Video Memory Size: %%b
if !tee! == 3 echo Current Setting: %%b
) ) else (
ping /n 2 127.1>nul
goto Graphics Card
)
set /p var=Do you need additional information?(y/n):
if /i %var% == y notepad "%TEMP%\temp.txt"
del /f "%TEMP%\temp.txt" 2>nul
pause
|
|
2007-11-25 15:39 |
|
|
htysm
高级用户
   
积分 866
发帖 415
注册 2005-12-4
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
楼上的批处理真强,测试后发现有误差,双核的说是单核的,硬盘是串口的说是IDE的。
The batch script upstairs is really powerful. After testing, it was found that there are errors. Those with dual - core are said to be single - core, and those with serial hard drives are said to be IDE.
|

欢迎你到批处理爱好者联盟QQ群:18023953 |
|
2007-11-25 16:29 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
    『第 10 楼』:
使用 LLM 解释/回答一下
26933062兄我整理了点Wmic节点放在网络日志那,去查查,你CMD也很强,自己去get其他类型后for下就出来了
http://www.cn-dos.net/forum/viewthread.php?tid=35681&fpage=1
CPU
@echo off
wmic path Win32_Processor Get Caption,name,L2CacheSize,ExtClock,MaxClockSpeed /format:list
pause
Video
@echo off
WMIC PATH Win32_VideoController Get name,VideoModeDescription,CurrentRefreshRate,CurrentBitsPerPixel /format:list
pause
Brother 26933062, I've organized some Wmic nodes and placed them in the network log. Go check it out. Your CMD is also very powerful; you can go get other types and then use for to get the result.
http://www.cn-dos.net/forum/viewthread.php?tid=35681&fpage=1
CPU
@echo off
wmic path Win32_Processor Get Caption,name,L2CacheSize,ExtClock,MaxClockSpeed /format:list
pause
Video
@echo off
WMIC PATH Win32_VideoController Get name,VideoModeDescription,CurrentRefreshRate,CurrentBitsPerPixel /format:list
pause
|

第一高手 第二高手
我的小站
 |
|
2007-11-25 17:16 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
|
2007-11-25 17:49 |
|
|
haiou327
高级用户
    DOS时空
积分 713
发帖 348
注册 2007-2-10
状态 离线
|
|
2007-11-25 19:53 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
多谢 fastslz 兄的热情,
一直想了解wmic,但因为不识英文,对wmic一直是摸不着边。
有了兄的整理资料,一定对我大有帮助。
谢谢!!!
Thanks to the enthusiasm of brother fastslz, I've always wanted to understand wmic, but because I don't know English, I've been completely at a loss with wmic. With your sorted-out materials, it must be of great help to me. Thanks!!!
|

致精致简! |
|
2007-11-26 01:45 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
WMIC从命令行对Windows的全面管理
从Windows 2000开始,WMI(Windows 管理规范)就是Windows系统管理的重要组成部分。WMIC是Windows Management Instrumentation Command-line的简称,在WMIC出现之前,要从命令行访问WMI数据库或WMI名称空间不是一件容易的事情。现在,WMIC利用WMI强大的功能把系统管理扩展到了命令行。
一、什么是WMIC?
WMIC扩展WMI,提供了从命令行接口和批命令脚本执行系统管理的支持。在WMIC出现之前,如果要管理WMI系统,必须使用一些专门的WMI应用,例如SMS,或者使用WMI的脚本编程API,或者使用象CIM Studio之类的工具。如果不熟悉C++之类的编成语言或VBScript之类的脚本语言,或者不掌握WMI名称空间的基本知识,要用WMI管理系统是很困难的。WMIC改变了这种情况,为WMI名称空间提供了一个强大的、友好的命令行接口。
WMIC比WMI简单、直观得多,这主要是由于使用了别名(Alias)。别名机制获取用户在命令行上输入的一些简单命令,按照预定义的方式操作WMI名称空间,例如根据一个简单的WMIC别名Get命令构造出一个复杂的WMI查询语言(WQL)命令。从这个意义上看,别名是用户和名称空间之间一个简化操作的中间层。例如,如果在WMIC命令行上执行下面这个简单的WMIC命令,就可以获得用户帐户的基本信息:
useraccount list brief
在上面的命令中,Useraccount别名执行了一个Win32_Useraccount类的WQL查询,以文本的形式显示出从该类提取的信息。另外,WMIC还以文本的形式显示出Win32_Useraccount类的属性。除了文本形式的输出之外,WMIC还能够以其他形式返回命令执行结果,例如XML、HTML或者CSV(逗号分隔的文本文件)。
WMIC以WMI模式中类的实例的形式保存别名。默认的别名类——MSFT_CliAlias,以及其他支持WMIC的类保存在模式的默认名称空间,或者说root\cli角色。角色可以简单地看成专门用来支持WMIC的另一个WMI名称空间。默认角色root\cli连接到root\cimv2名称空间,操作root\cimv2之内的类。虽然使用WMIC时一般不需要用到CIM Studio,但CIM Studio可以用来方便地查看root\cli名称空间。
你可以向root\cli名称空间和其他名称空间加入新的别名,还可以用Class和Path命令直接访问WMI名称空间,本文后面将详细说明Class和Path命令。
二、运行WMIC
执行“wmic”命令启动WMIC命令行环境。这个命令可以在XP或.NET Server的标准命令行解释器(cmd.exe)、Telnet会话或“运行”对话框中执行。这些启动方法可以在本地使用,也可以通过.NET Server终端服务会话使用。
第一次执行WMIC命令时,Windows首先要安装WMIC,然后显示出WMIC的命令行提示符。在WMIC命令行提示符上,命令以交互的方式执行。例如,执行下面的命令将关闭正在运行的Outlook:
process where name='outlook.exe' call terminate
命令运行结束后,WMIC命令行提示符重新出现。每个命令必须在一行之内输入,中间不能插入换行符。
WMIC也可以按照非交互的模式运行。如果要执行某个单步的任务,或者运行批命令中的一系列WMIC命令,非交互模式就很有用。要使用非交互模式,只要在同一个命令行上启动WMIC并输入要执行的命令就可以了。例如,执行cmd.exe打开一个命令行窗口,然后执行下面的命令,就可以输出连接到MACHINE1的打印机清单:
wmic /node:MACHINE1 printer list status
在这个例子中,第一个操作是启动WMIC,然后是根据/node参数建立一个到MACHINE1的远程连接,最后执行一个WMIC命令显示出打印机状态信息。命令运行结束后,返回到Windows命令行提示符状态。
安装了WMIC的机器可以连接到任何一台安装了WMI的机器,被连接的机器不需要安装WMIC。例如,从一台运行Win XP Pro的机器启动WMIC,可以连接和管理所有运行着XP、Win2K、Windows NT 4.0、Windows Me和Windows 9x的机器。
三、WMIC命令行构成
WMIC提供了大量的全局开关、别名、动词、命令和丰富的命令行帮助增强用户接口。全局开关是适用于整个WMIC会话的配置选项。例如,/trace:on开关启用错误跟踪机制,如果这个开关处于打开状态,WMIC返回每一个命令的错误信息。利用/note开关可以访问远程机器,/interactive:on开关要求WMIC在执行删除操作之前提示确认,其他的全局开关还包括/role、/user、/implevel以及/namespace。
如前所述,别名是用户和WMI名称空间一个简化语法的中间层。当你指定一个别名时,动词(Verb)表示要执行的动作。例如,前面例子中的List和Call就是两个动词的例子。表一描述了其他一些WMIC动词,并为每一个动词给出了例子。
表一:WMIC动词
动词 例子 说明
Assoc group where name= 'administrators' assoc 显示出Administrators组与系统的所有关联,包括Administrators组成员等。又如,os assoc显示出有关操作系统的信息和已经安装的补丁。
Create environment create name="progloc", username="work01\User1",variablevalue= "%programfiles%\prog01" 创建一个名字为Progloc的变量,把它的值设置为Program Files文件夹的一个子文件夹,把这个变量加入到Work01工作组计算机User1帐户。
Delete environment where(name= "progloc") delete 删除Progloc环境变量。测试WMIC命令时,为了防止意外地删除,可以使用/interactive:on全局开关,这时删除之前会要求确认。
Get partition get bootpartition, description, deviceid, bootable 返回分区是否可启动、描述信息和设备ID属性等信息。
Set path WIN32_USERACCOUNT where(name="user01") set disabled="true" 在成员服务器或工作站上禁用User01用户帐户。
命令用来控制对WMIC和WMI名称空间的访问。注意表一的最后一个例子,这个例子用的是Path和Win32_USERACCOUNT类,而不是Useraccount别名。Path是一个直接访问WMI名称空间中实例的命令,不必再通过别名访问。如果待执行的系统管理任务没有现成的别名可用,Path命令特别有用。虽然你可以用新的别名和角色扩展WMIC,但如果你对WMI名称空间比较熟悉,使用Path命令也很方便。
除了Path命令之外,WMIC还支持Class、Context、Quit和Exit命令。Class命令用来直接访问WMI模式内的类或创建现有类的实例。Class命令和Path命令的不同之处在于,Path命令的作用对象是实例以及它的属性(例如,提取管理用的信息),而Class命令的作用对象是类的定义。例如,如果要提取出WIN32_SOFTWAREELEMENT类的所有属性,可以执行如下命令:
class WIN32_SOFTWAREELEMENT get
这个命令的输出是HTML格式,稍后我们将了解如何用/output全局开关把输出重定向到可用浏览器打开的HTML文件。Class命令加上Assoc动词能够显示出类的名称空间路径以及其他与该类关联的类。利用Class命令可以删除类、创建类的实例,但不能创建类。
Context命令显示出全局开关的当前设置。Quit和Exit命令用来退出WMIC命令提示符环境,返回以前的Shell环境(例如Telnet环境,或XP的命令行提示符环境)。
命令行帮助是熟悉WMIC的有效途径。表二是在WMIC提示符下查找信息的常用命令:
四、实践应用
以上我们了解了WMIC命令行环境的基础知识,下面来看看如何用批命令运行WMIC,以及把输出结果定向到控制台或HTML、XML文件。从批命令文件运行WMIC的好处在于不需要重复输入一系列复杂的命令,例如,下面是一个批命令文件的内容,它的作用是显示出MACHINE1和MACHINE2这两台机器的CPU信息,输出结果显示在控制台上。/format开关是面向动词的开关,而不是全局开关,它只用于Get和List动词。
wmic /node:MACHINE1, MACHINE4 cpu get name, caption,
maxclockspeed, systemname /format:textvaluelist.xsl
WMIC批命令可以使用变量。也就是说,对于上面的批命令,服务器的名字不仅可以直接指定,而且还可以通过%1、%2的形式指定,下面就是一个例子。把下面的代码放入一个批命令文件,然后在执行批命令文件时加上一到二个机器的名字即可;另外,也可以创建一个独立的文本文件,然后在文本文件中放入机器名字的清单,清单可以是CSV格式,或用换行符分隔的格式。如果使用独立的文本文件提供机器名字,只需在/node全局开关后面加上以@符号为前缀的文本文件名字,@符号告诉/node开关后面的参数是一个文件名字而不是机器名字。
@echo off
if "%1"=="" goto msg
if "%2"=="" goto single
wmic /node:%1, %2 cpu get name, caption, maxclockspeed, systemname
/format:textvaluelist.xsl
goto end
:single
wmic /node:%1 cpu get name, caption, maxclockspeed,
systemname /format:textvaluelist.xsl
goto end
:msg
echo 必须指定至少一台计算机的名字。
:end
如前所述,WMIC命令的输出结果不仅可以发送到控制台,还可以发送到XML或HTML、MOF(Managed Object Format)格式的文件。在安装了WMI的计算机上,MOF是WMI数据库中类和类实例的原始保存形式。下面的例子显示了如何把MACHINE4处理器信息的查询结果输出到HTML文件,/output全局开关要求WMIC把输出发送到file1.htm,/format开关要求WMIC把原始的XML输出转换成HTML格式。用来转换格式的XSL样式文件既可以是自定义的,也可以是任何安装了WMIC的机器上\%systemroot%\system32\wbem文件夹下面的任意XSL文件。例如,利用csv.xsl样式文件可以把输出结果转换成CSV格式,利用htable.xsl样式可以构造出一个包含结果数据的表格。
wmic /node:MACHINE4 /output:e:\file1.htm cpu get description,
maxclockspeed, extclock, manufacturer, revision /format:hform.xsl
前面已经提到,Class命令加上Get动词的默认输出是HTML格式。因此,如果要把这类命令的输出结果保存到HTML文件,只需指定/output开关,不必加上/format开关。/record和/append全局开关也能够从WMIC命令行截取信息,请利用WMIC的命令行帮助功能了解有关这些开关的更多信息。
如果要以XML格式输出,用/translate开关和Basicxml关键词把大于符号“>”和小于符号“<”转换成XML中有意义的字符。下面是输出XML的一个例子,输出的XML数据可导入到数据库或其他能够理解XML标记的系统。下面代码的输出中包含了WMIC命令、命令行请求参数、目标节点、全局开关以及命令执行结果。
wmic cpu get maxclockspeed /translate:basicxml /format:rawxml.xsl
总之,WMIC是XP和.NET Server中命令行管理功能的一次重要改进,对于从命令行访问和管理WMI名称空间提供了强健的支持。虽然掌握和熟悉WMIC命令行环境需要一段时间,但只要你熟悉了它,一个系统管理的全新境界将展现在你的面前。
WMIC: Comprehensive Management of Windows from the Command Line
Starting from Windows 2000, WMI (Windows Management Instrumentation) has been an important part of Windows system management. WMIC is the abbreviation of Windows Management Instrumentation Command-line. Before the appearance of WMIC, it was not an easy task to access the WMI database or WMI namespace from the command line. Now, WMIC uses the powerful functions of WMI to extend system management to the command line.
1. What is WMIC?
WMIC extends WMI and provides support for performing system management from the command line interface and batch command scripts. Before the appearance of WMIC, if you wanted to manage the WMI system, you had to use some specialized WMI applications, such as SMS, or use the WMI scripting programming API, or use tools like CIM Studio. If you were not familiar with programming languages like C++ or scripting languages like VBScript, or did not master the basic knowledge of the WMI namespace, it was very difficult to manage the system with WMI. WMIC has changed this situation and provided a powerful and friendly command line interface for the WMI namespace.
WMIC is much simpler and more intuitive than WMI, mainly due to the use of aliases. The alias mechanism obtains some simple commands entered by the user on the command line and operates the WMI namespace in a predefined way. For example, a complex WMI Query Language (WQL) command is constructed according to a simple WMIC alias Get command. In this sense, the alias is an intermediate layer that simplifies the operation between the user and the namespace. For example, if you execute the following simple WMIC command on the WMIC command line, you can obtain the basic information of the user account:
useraccount list brief
In the above command, the Useraccount alias executes a WQL query of the Win32_Useraccount class and displays the information extracted from this class in text form. In addition, WMIC also displays the attributes of the Win32_Useraccount class in text form. In addition to text-form output, WMIC can also return the command execution result in other forms, such as XML, HTML, or CSV (comma-separated text file).
WMIC saves aliases in the form of instances of classes in the WMI schema. The default alias class - MSFT_CliAlias, and other classes supporting WMIC are saved in the default namespace of the schema, or the root\cli role. The role can be simply regarded as another WMI namespace specially used to support WMIC. The default role root\cli is connected to the root\cimv2 namespace and operates the classes within root\cimv2. Although CIM Studio is generally not needed when using WMIC, CIM Studio can be used to conveniently view the root\cli namespace.
You can add new aliases to the root\cli namespace and other namespaces, and you can directly access the WMI namespace using the Class and Path commands. The Class and Path commands will be described in detail later in this article.
2. Running WMIC
Execute the "wmic" command to start the WMIC command line environment. This command can be executed in the standard command line interpreter (cmd.exe) of XP or.NET Server, Telnet session, or "Run" dialog box. These startup methods can be used locally or through a.NET Server terminal services session.
When executing the WMIC command for the first time, Windows will first install WMIC, and then display the WMIC command line prompt. On the WMIC command line prompt, commands are executed interactively. For example, executing the following command will close the running Outlook:
process where name='outlook.exe' call terminate
After the command is executed, the WMIC command line prompt reappears. Each command must be entered in one line, and no line breaks can be inserted in the middle.
WMIC can also run in non-interactive mode. Non-interactive mode is useful if you want to perform a single-step task or run a series of WMIC commands in a batch command. To use non-interactive mode, just start WMIC on the same command line and enter the command to be executed. For example, open a command line window by executing cmd.exe, and then execute the following command to output the list of printers connected to MACHINE1:
wmic /node:MACHINE1 printer list status
In this example, the first operation is to start WMIC, then establish a remote connection to MACHINE1 according to the /node parameter, and finally execute a WMIC command to display the printer status information. After the command is executed, it returns to the Windows command line prompt state.
A machine with WMIC installed can connect to any machine with WMI installed, and the connected machine does not need to install WMIC. For example, starting WMIC from a machine running Win XP Pro can connect and manage all machines running XP, Win2K, Windows NT 4.0, Windows Me, and Windows 9x.
3. Composition of the WMIC Command Line
WMIC provides a large number of global switches, aliases, verbs, commands, and rich command line help to enhance the user interface. Global switches are configuration options applicable to the entire WMIC session. For example, the /trace:on switch enables the error tracking mechanism. If this switch is on, WMIC returns the error information of each command. The /note switch can be used to access a remote machine, the /interactive:on switch requires WMIC to prompt for confirmation before performing a delete operation. Other global switches include /role, /user, /implevel, and /namespace.
As mentioned earlier, the alias is an intermediate layer that simplifies the syntax between the user and the WMI namespace. When you specify an alias, the verb indicates the action to be performed. For example, List and Call in the previous example are examples of two verbs. Table 1 describes some other WMIC verbs and gives examples for each verb.
Table 1: WMIC Verbs
Verb Example Description
Assoc group where name= 'administrators' assoc Displays all associations between the Administrators group and the system, including members of the Administrators group, etc. Also, os assoc displays information about the operating system and installed patches.
Create environment create name="progloc", username="work01\User1",variablevalue= "%programfiles%\prog01" Creates a variable named Progloc, sets its value to a subfolder of the Program Files folder, and adds this variable to the User1 account of the Work01 workgroup computer.
Delete environment where(name= "progloc") delete Deletes the Progloc environment variable. When testing WMIC commands, to prevent accidental deletion, you can use the /interactive:on global switch, which will require confirmation before deletion.
Get partition get bootpartition, description, deviceid, bootable Returns information such as whether the partition is bootable, description information, and device ID attributes.
Set path WIN32_USERACCOUNT where(name="user01") set disabled="true" Disables the User01 user account on a member server or workstation.
Commands are used to control access to WMIC and the WMI namespace. Note the last example in Table 1. This example uses the Path and Win32_USERACCOUNT class, not the Useraccount alias. The Path is a command to directly access an instance in the WMI namespace, and there is no need to access it through an alias. The Path command is especially useful when there is no ready-made alias available for the system management task to be performed. Although you can extend WMIC with new aliases and roles, if you are familiar with the WMI namespace, using the Path command is also convenient.
In addition to the Path command, WMIC also supports the Class, Context, Quit, and Exit commands. The Class command is used to directly access classes in the WMI schema or create instances of existing classes. The difference between the Class command and the Path command is that the Path command acts on instances and their attributes (for example, extracting information for management), while the Class command acts on the definition of classes. For example, if you want to extract all attributes of the WIN32_SOFTWAREELEMENT class, you can execute the following command:
class WIN32_SOFTWAREELEMENT get
The output of this command is in HTML format. Later, we will learn how to use the /output global switch to redirect the output to an HTML file that can be opened with a browser. The Class command plus the Assoc verb can display the namespace path of the class and other classes associated with this class. The Class command can be used to delete classes and create instances of classes, but cannot create classes.
The Context command displays the current settings of global switches. The Quit and Exit commands are used to exit the WMIC command prompt environment and return to the previous Shell environment (for example, the Telnet environment or the XP command line prompt environment).
Command line help is an effective way to become familiar with WMIC. Table 2 is a common command for finding information under the WMIC prompt:
4. Practical Application
We have learned the basic knowledge of the WMIC command line environment above. Now let's see how to run WMIC with a batch command and redirect the output result to the console or to HTML, XML files. The advantage of running WMIC from a batch command file is that you don't need to repeatedly enter a series of complex commands. For example, the following is the content of a batch command file, which is used to display the CPU information of two machines, MACHINE1 and MACHINE4, and the output result is displayed on the console. The /format switch is a verb-oriented switch, not a global switch, and it is only used for the Get and List verbs.
wmic /node:MACHINE1, MACHINE4 cpu get name, caption,
maxclockspeed, systemname /format:textvaluelist.xsl
WMIC batch commands can use variables. That is to say, for the above batch command, the name of the server can not only be specified directly, but also can be specified in the form of %1, %2. The following is an example. Put the following code into a batch command file, and then add one or two machine names when executing the batch command file; in addition, you can also create an independent text file, and then put the list of machine names in the text file. The list can be in CSV format or in a format separated by line breaks. If an independent text file is used to provide the machine names, just add the text file name prefixed with the @ symbol after the /node global switch. The @ symbol tells the /node switch that the parameter behind is a file name, not a machine name.
@echo off
if "%1"=="" goto msg
if "%2"=="" goto single
wmic /node:%1, %2 cpu get name, caption, maxclockspeed, systemname
/format:textvaluelist.xsl
goto end
:single
wmic /node:%1 cpu get name, caption, maxclockspeed,
systemname /format:textvaluelist.xsl
goto end
:msg
echo 必须指定至少一台计算机的名字。
:end
As mentioned earlier, the output result of the WMIC command can not only be sent to the console, but also to XML or HTML, MOF (Managed Object Format) format files. On a computer with WMI installed, MOF is the original storage form of classes and class instances in the WMI database. The following example shows how to output the query result of the processor information of MACHINE4 to an HTML file. The /output global switch requires WMIC to send the output to file1.htm, and the /format switch requires WMIC to convert the original XML output into HTML format. The XSL style file used for format conversion can be a custom one or any XSL file in the \%systemroot%\system32\wbem folder on any machine with WMIC installed. For example, using the csv.xsl style file can convert the output result into CSV format, and using the htable.xsl style can construct a table containing the result data.
wmic /node:MACHINE4 /output:e:\file1.htm cpu get description,
maxclockspeed, extclock, manufacturer, revision /format:hform.xsl
As mentioned earlier, the default output of the Class command plus the Get verb is in HTML format. Therefore, if you want to save the output result of such a command to an HTML file, you only need to specify the /output switch, and there is no need to add the /format switch. The /record and /append global switches can also intercept information from the WMIC command line. Please use the command line help function of WMIC to learn more about these switches.
If you want to output in XML format, use the /translate switch and the Basicxml keyword to convert the greater-than symbol ">" and the less-than symbol "<" into meaningful characters in XML. The following is an example of outputting XML. The output XML data can be imported into a database or other systems that can understand XML tags. The output of the following code includes the WMIC command, the command line request parameters, the target node, the global switches, and the command execution result.
wmic cpu get maxclockspeed /translate:basicxml /format:rawxml.xsl
In conclusion, WMIC is an important improvement in the command line management function in XP and.NET Server, and provides robust support for accessing and managing the WMI namespace from the command line. Although it takes some time to master and be familiar with the WMIC command line environment, once you are familiar with it, a brand new realm of system management will be presented to you.
|
|
2007-11-26 02:27 |
|
|
Jneny
高级用户
    中國DOS聯盟常任參議员
积分 686
发帖 318
注册 2005-11-4
状态 离线
|
|
2007-12-6 15:15 |
|
|