记录用到的wmic语句

来源:互联网 发布:vba数据录入 编辑:程序博客网 时间:2024/06/05 05:06

1. 查看本机IP:

先查网卡的索引号:wmic nic where NetConnectionID="本地连接" get index

得到索引号为11,再查IP地址:wmic nicconfig where index=11 get IPAddress /value,结果:

IPAddress={"192.168.2.96","fe80::48:89c9:4cd4:d0c8"}
我只想要IP,不需要MAC地址,也许有更好的方法显示IP。

2. 查看和开户远程桌面服务

(参考 http://blogs.msdn.com/b/rds/archive/2006/10/03/terminal-services-_2800_ts_2900_-remote-configuration-primer-part-1.aspx )

新装win7,无鼠标,通过wmic开户远程桌面服务。先查看服务状态:

wmic service where Name="TermService" get Started, StartMode

Started  StartModeFALSE    Manual
开启服务,设置为自动启动(在windows 7里以下2条命令不能直接在cmd.exe下运行,会提示拒绝访问的错误,以管理员身份登录也不行。我的解决方法是以管理员身份运行C:\Windows\SysWOW64\cmd.exe。),以下几条命令都在管理员身份的cmd.exe里运行:

C:\Windows\system32>wmic service where Name="TermService" call StartServiceExecuting (\\B-PC\ROOT\CIMV2:Win32_Service.Name="TermService")->StartService() Method execution successful.Out Parameters:instance of __PARAMETERS{        ReturnValue = 0;};


C:\Windows\system32>wmic service where Name="TermService" set StartMode="Auto"Updating property(s) of '\\B-PC\ROOT\CIMV2:Win32_Service.Name="TermService"' Property(s) update successful.

但是StartMode的修改无效,不知道为什么?

C:\Windows\system32>wmic service where Name="TermService" get Started, StartModeStarted  StartModeTRUE     Manual

除了开启服务,还要设置允许来自远程的连接:

C:\Windows\system32>wmic RDToggle where servername="SHENTAO-PC" call SetAllowTSConnections 1Executing (\\SHENTAO-PC\ROOT\CIMV2\TerminalServices:Win32_TerminalServiceSetting.ServerName="SHENTAO-PC")->SetAllowTSConnections()Method execution successful.Out Parameters:instance of __PARAMETERS{        ReturnValue = 0;};


3. 查看本机安装的安全补丁。

以下命令列出所有已经安装的update、security update、service pack

wmic qfe

wmic qfe  where fixcomments!=""
我的windows 2003上wmic qfe命令的结果里出现很多fixcomments字段为空的行,要把这些行过滤掉。

关于qfe的官方解释:http://msdn.microsoft.com/en-US/library/ms913256(v=WinEmbedded.5).aspx

显示已经安装补丁的KB号:

wmic qfe where fixcomments!="" get hotfixid /value



4. 管理已安装程序

查看已经安装的程序:

wmic product
查找Adobe Reader:
wmic product where Name="Adobe Reader 9.4.7 MUI"
卸载程序:

wmic product where Name="Adobe Reader 9.4.7 MUI" call uninstall
返回结果:

Executing (\\B-PC\ROOT\CIMV2:Win32_Product.IdentifyingNumber="{AC76BA86-7AD7-FFFF-7B44-A91000000001}",Name="Adobe Reader 9.4.7 MUI",Version="9.4.7")->Uninstall()Method execution successful.Out Parameters:instance of __PARAMETERS{        ReturnValue = 0;};













原创粉丝点击