[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[原创] 一起学习批处理命令wmic

==================================== > Novaa 原创。转载请注明 Novaa @bbs.bathome.net <======================

一。引言:
如果让大家获取系统的进程信息。大家会用那个命令。呵呵。是tasklist 吧。如果要终止系统自代的计算机进程。大家会怎么写?[code
taskkill /im calc.exe /f>nul[/code]
如果要修改本机IP(假设改为192.168.1.20)。大家怎么改?
  1. netsh interface ip set address name="本地连接" source=static addr=192.168.1.20 mask=255.255.255.0
复制代码
呵呵。
那么。有 没有其他命令呢?答案是肯定的,这些都可以用wmic来完成。
获取进程。结束进程。修改IP对应的命令分别为
  1. wmic process list brief
  2. wmic process where name="Wscript.exe" call terminate
  3. wmic nicconfig where (index='1') call enablestatic "192.168.1.81","255.255.255.0"   
复制代码
不知道为什么。第三个为什么执行不成功?!格式都正确。设置为index=9也不行。。先不管他了。

二。WMIC简介。
Windows Management Instrumentation 命令行 (WMIC) 提供了简单的 Windows Management Instrumentation (WMI) 命令行界面,这样您可利用 WMI 来管理运行 Microsoft Windows 的计算机。WMIC 与现有命令行程序和实用程序命令相互操作,且很容易通过脚本或其他面向管理的应用程序来扩展 WMIC。
WMI 提供程序允许使用 WMI 管理大量的硬件组件、操作系统子系统和应用程序系统。WMIC 可与由这些 WMI 提供程序执行的所有模式一起使用。
WMIC 可用于远程管理作为 Windows 域成员且具有 WMI 的任何计算机。对 WMIC 而言,不必为了管理远程管理的计算机而使其在该远程管理的计算机上可用。

三。WMIC全局开关。别名。动词。
1。)WMIC的全局开关
全局开关用于设置 WMIC 环境的默认值。可通过输入 CONTEXT 命令查看由全局开关设置的当前条件值。
WMIC的全局开关有
  1. /NAMESPACE 别名使用的名称空间路径。
  2. /ROLE 包含此别名定义的角色路径。
  3. /NODE 别名使用的服务器。
  4. /IMPLEVEL 客户模拟级别。
  5. /AUTHLEVEL 客户身份验证级别。
  6. /LOCALE 客户应用的语言识别符。
  7. /PRIVILEGES 启用或禁用所有特权。
  8. /TRACE 将调试信息输出到 stderr。
  9. /RECORD 将所有输入命令和输出写入日志。
  10. /INTERACTIVE 设置或重设交互模式。
  11. /FAILFAST 设置或重置 FailFast 模式。
  12. /USER 会话期间使用的用户。
  13. /PASSWORD 用于会话登录的密码。
  14. /OUTPUT 为输出重新定向指定模式。
  15. /APPEND 为输出重新定向指定模式。
  16. /AGGREGATE 设置或重置集合模式。
  17. /AUTHORITY Specifies the for the connection.
复制代码
关于具体的使用。大家可以用 /?看咯。(随风版主的名言。自己调试去。哈哈)

2。)WMIC的别名
别名是运行 WMIC 时帮助您访问 WMI 基础结构的一种辅助手段。别名是友好名称,用来捕获与一些特定的任务(如磁盘或网络管理)相关联的 WMI 类别的特征。
WMIC中的别名有:
  1. ALIAS - 访问本地机器上的别名
  2. BASEBOARD - 基板 (也叫母板或系统板) 管理。
  3. BIOS - 基本输入/输出服务 (BIOS) 管理。
  4. BOOTCONFIG - 启动配置管理。
  5. CDROM - CD-ROM 管理。
  6. COMPUTERSYSTEM - 计算机系统管理。
  7. CPU - CPU 管理。
  8. CSPRODUCT - SMBIOS 的计算机系统产品信息。
  9. DATAFILE - DataFile 管理。
  10. DCOMAPP - DCOM 程序管理。
  11. DESKTOP - 用户桌面管理。
  12. DESKTOPMONITOR - 监视器管理。
  13. DEVICEMEMORYADDRESS - 设备内存地址管理。
  14. DISKDRIVE - 物理磁盘驱动器管理。
  15. DISKQUOTA - NTFS 卷磁盘空间使用情况。
  16. DMACHANNEL - 直接内存访问(DMA)频道管理。
  17. ENVIRONMENT - 系统环境设置管理。
  18. FSDIR - 文件目录系统项目管理。
  19. GROUP - 组帐户管理。
  20. IDECONTROLLER - IDE 控制器管理。
  21. IRQ - 间隔请求线 (IRQ) 管理。
  22. JOB - 提供对使用计划服务安排的工作的访问。
  23. LOADORDER - 定义执行依存的系统服务管理。
  24. LOGICALDISK - 本地储存设备管理。
  25. LOGON - 登录会话。
  26. MEMCACHE - 缓存内存管理。
  27. MEMLOGICAL - 系统内存管理 (配置布局和内存可用性)。
  28. MEMPHYSICAL - 计算机系统物理内存管理。
  29. NETCLIENT - 网络客户端管理。
  30. NETLOGIN - (某一用户的)网络登录信息管理。
  31. NETPROTOCOL - 协议 (和其网络特点) 管理。
  32. NETUSE - 活动网络连接管理。
  33. NIC - 网络界面控制器 (NIC) 管理。
  34. NICCONFIG - 网络适配器管理。
  35. NTDOMAIN - NT 域管理。
  36. NTEVENT - NT 事件日志的项目
  37. NTEVENTLOG - NT 时间日志文件管理。
  38. ONBOARDDEVICE - 母板(系统板)内置普通设适配器设备的管理。
  39. OS - 已安装的操作系统管理。
  40. PAGEFILE - 虚拟内存文件对调管理。
  41. PAGEFILESET - 页面文件设置管理。
  42. PARTITION - 物理磁盘分区区域的管理。
  43. PORT - I/O 端口管理。
  44. PORTCONNECTOR - 物理连接端口管理。
  45. PRINTER - 打印机设备管理。
  46. PRINTERCONFIG - 打印机设备配置管理。
  47. PRINTJOB - 打印工作管理。
  48. PROCESS - 进程管理。
  49. PRODUCT - 安装包任务管理。
  50. QFE - 快速故障排除。
  51. QUOTASETTING - 设置卷的磁盘配额信息。
  52. RECOVEROS - 当操作系统失败时,将从内存收集的信息。
  53. REGISTRY - 计算机系统注册表管理。
  54. SCSICONTROLLER - SCSI 控制器管理。
  55. SERVER - 服务器信息管理。
  56. SERVICE - 服务程序管理。
  57. SHARE - 共享资源管理。
  58. SOFTWAREELEMENT - 安装在系统上的软件产品元素的管理。
  59. SOFTWAREFEATURE - SoftwareElement 的软件产品组件的管理。
  60. SOUNDDEV - 声音设备管理。
  61. STARTUP - 用户登录到计算机系统时自动运行命令的管理。
  62. SYSACCOUNT - 系统帐户管理。
  63. SYSDRIVER - 基本服务的系统驱动程序管理。
  64. SYSTEMENCLOSURE - 物理系统封闭管理。
  65. SYSTEMSLOT - 包括端口、插口、附件和主要连接点的物理连接点管理。
  66. TAPEDRIVE - 磁带驱动器管理。
  67. TEMPERATURE - 温度感应器的数据管理 (电子温度表)。
  68. TIMEZONE - 时间区域数据管理。
  69. UPS - 不可中断的电源供应 (UPS) 管理。
  70. USERACCOUNT - 用户帐户管理。
  71. VOLTAGE - 电压感应器 (电子电量计) 数据管理。
  72. VOLUMEQUOTASETTING - 将某一磁盘卷与磁盘配额设置关联。
  73. WMISET - WMI 服务操作参数管理。
复制代码
3。)WMIC的动词
大多数别名支持下列动词。别名还可能支持其他动词。要在 WMIC 中使用动词,请输入别名,后面跟动词。
WMIC里面的动词有:
  1. ASSOC
  2. CALL
  3. CREATE
  4. DELETE
  5. GET
  6. LIST
  7. SET
复制代码
关于动词。下面是我在微软的网站上找到的资料(我自己整理出来的。不好复制。。):
  1. WMIC Verbs:
  2. Most aliases support the following verbs.Aliases might also support other verbs.To use verbs in WMIC,enter the alisa name followed by the verb.For more infortion about /?,see "Aliases" in help.If an alias does not support a verb,you receive the message "provide is not capable of the attempted operation."
  3. Verb
  4. 1.ASSOC
  5. Action:
  6. ---1.Return the result of the query:Associators of {} Where is the path of objects returned by the PATH or CLASS commands. The results are instances associated with the object. When ASSOC is used with an alias, the classes associated with the class underlying the alias are returned. By default, the output for class is in TABLE format. See the following table of switches for /ASSOC.
  7. Parameters or Verb-specific switches:
  8. ---2.Optionally, an output file format, such as LIST, MOF, or other.
  9. Example
  10. ---3.OS ASSOC
  11. 2.CALL
  12. Action:
  13. ---1.Executes methods.
  14. Parameters or Verb-specific switches:
  15. ---2.Method and parameter list if appropriate. Parameter lists are comma delimited. Use SERVICE CALL /? to get a list of available methods and their parameters for the current alias.
  16. Example
  17. ---3.SERVICE WHERE CAPTION='TELNET' CALL STARTSERVICE
  18. 3.CREATE
  19. Action
  20. ---1.Creates a new instance and sets the property values for the new instance. This cannot be used to create a new class.
  21. Parameters or Verb-specific switches:
  22. ---2.Properties equated to values, delimited with commas. Use CREATE /? for a list of property names for the alias.
  23. Example
  24. ---3.ENVIRONMENT CREATE Name="WMIC_test",VariableValue="WMIC_test_value",UserName="SYSTEM"
  25. 4.GET
  26. Action:
  27. ---1.Get specific properties.
  28. Parameters or Verb-specific switches:
  29. ---2.Property name or switch. See the table of switches for /GET below. Also use GET /? for a list of property names and switches for the alias.
  30. Example:
  31. ---3.PROCESS GET NAME
  32. 5.LIST
  33. Action:
  34. ---1.Show data. LIST is the default verb.
  35. Parameters or Verb-specific switches:
  36. ---2.See the following tables of adverbs and switches for LIST.
  37. Example:
  38. ---3.PROCESS LIST BRIEF
  39. 6.SET
  40. Actions
  41. ---1.Property set operations.
  42. Parameters or Verb-specific switches:
  43. ---2.Properties equated to values, delimited with commas. Use SET /? for a list of property names for the alias.
  44. Example:
  45. ---3.ENVIRONMENT WHERE Name="WMIC_test" SET VariableValue="WMIC_test_value1"
  46. The List verb has the following adverbs. To use adverbs in WMIC, enter the alias name followed by a verb and adverb. For more information about /?, see "Aliases" in Help.
  47. Adverb: A core set of the properties.
  48. BRIEF: The full set of properties. This is the default set of LIST properties.
  49. FULL: The instance paths only.
  50. INSTANCE: The status and related properties of the object.
  51. STATUS: System properties.
  52. SYSTEM: System properties.
  53. Alias-specific or user format: Alias-specific or user defined formats might be defined by providing distinct lists of properties and a format to be used in displaying them.
  54. WRITEABLE: The writeable properties of the objects.
  55. The List verb has the following switches. To use verb-specific switches in WMIC, enter the alias name followed by a switch (verbs and adverbs might also be used). For more information about /?, see "Aliases" in Help.
  56. Switch:
  57. /TRANSLATE:: Translate the output using the translation table named by the command. BasicXml and NoComma are translation tables included with WMIC.
  58. /EVERY:: Repeat the command every X seconds; X is determined by the interval
  59. /FORMAT:: Specify a keyword or XSL file name to format the data, as explained in the following note.
  60. The Get verb has the following switches.
  61. 1./VALUE: The output is formatted with each value listed on a separate line and with the name of the property.
  62. 2./ALL: The output is formatted as a table. The default output format is /ALL.
  63. 3./TRANSLATE:: Translate the output using the translation table named by the command. BasicXml and NoComma are translation tables included with WMIC.
  64. 4./EVERY:: Return values every X seconds, X is the interval.
  65. 5./FORMAT:: Specify a keyword or an XSL file name to format the data, as explained in the following note.
  66. The Assoc verb has the following switches.
  67. 1./RESULTCLASS:: The returned endpoints associated with the source object must belong to or be derived from the specified class.
  68. 2./RESULTROLE:: The returned endpoints must play a particular role in their association with the source object.
  69. 3./ASSOCCLASS: The returned endpoints must be associated with the source through the specified class or one of its derived classes.
  70. Notes
  71. • For both the LIST and GET verbs, the format specifier is used to designate either the name of an XSL file or the standard formats TABLE or LIST. /FORMAT:TABLE is equivalent to /ALL, which is the default output format.
  72. • MOF-formatted output can be captured to a file (using the /RECORD switch) and the file can be compiled using Mofcomp.exe on another computer to import it into WMI on the other system. However, make sure that computer-specific properties are edited as appropriate for the other computer.
  73. • The order of the /FORMAT and /TRANSLATE switches is important. If /TRANSLATE follows /FORMAT, the output is formatted and then translated. If /FORMAT follows /TRANSLATE, the output is translated and then formatted.
  74. Examples
  75. The following examples demonstrate the effective use of the verbs and their adverbs and switches.
  76. • PROCESS GET NAME /FORMAT:XML.XSL /TRANSLATE:BASICXML
  77. The process names are output in XML format. Without the /TRANSLATE switch, the characters around the values are displayed as their HTML equivalents.
  78. • PROCESS WHERE Handle="0" ASSOC
  79. The instances associated with a specific object (unlike the classes associated with an alias) are returned.
复制代码
待续。。。

[ 本帖最后由 novaa 于 2007-12-30 00:09 编辑 ]
ㄗs:A good programming is 99% sweat and 1% coffee!--①個亾

============ >   hi.baidu.com/novaa   <============

好贴,慢慢看这个强大的wmic。

TOP

谢谢楼主分享!期待下文啊

TOP

论坛里还有很多这方面的资料.....

TOP

看不会 慢慢学
简单

TOP

TOP

不知道为什么在有的电脑上输入wmic安装后就可以使用,而有的电脑不能使用该命令,即使将wmic.exe复制到其system32目录下!

TOP

wmic 这是新东西呀。

TOP

这个命令好强。

TOP

功能太强大了,就是有好多基础的要掌握好!

TOP

返回列表