It took a long time in MS Technet to see the "Script of Scripts", the article is very vivid and humorous, if all technical articles are written in this easy way.
WMI - Windows Management Instrumentation Related Links:
Microsoft "Script Guide": http://www.microsoft.com/china/technet/community/columns/scripts/default.mspxmsdn WMI Scripting Primer: http://www.microsoft.com/china/technet/archives/columns /scripts/sg0103.asp
Script Example 1, shows the machine total memory strComputer = Set wbemServices = GetObject ( "winmgmts: //" & strComputer) "." Set wbemObjectSet = wbemServices.InstancesOf ( "Win32_LogicalMemoryConfiguration") For Each wbemObject In wbemObjectSet WScript.Echo "Total Physical Memory (KB): "& wbemObject.totalphysicalMemoryNext
Script Example 2, Strcomputer = "."
Set objwmiservice = getObject ("WinMgmts: //" & strComputer & "/ root / cimv2")
Strwql = "SELECT *" & _ "from __instancecreationEvent" & _ "WITHIN 2" & _ "WHERE TARGETINSTANCE ISA 'WIN32_PROCESS'" & _ "and targetinstance.name = 'NOTEPAD.EXE'"
WScript.Echo "Waiting for a new instance of Notepad to start ..." Set objEventSource = objWMIService.ExecNotificationQuery (strWQL) Set objEventObject = objEventSource.NextEvent () WScript.Echo "A new instance of Notepad was just started."
Use the shell (shell) program set objshell = wscript.createObject ("wscript.shell") objshell.run "notepad" run notepad
Call the command program (% COMSPEC% environment variable calls the CMD.exe or Command.exe of the corresponding operating system "Run the script and keeps the console window: set objshell = creteObject (" wscript.shell ") objshell.run"% COMSPEC% / K ipconfig "
Use Objshell's Exec method instead of RUN methods to return a WSHScriptexec object, which can be displayed more control over the results. Run the script exam.vbs: Enter: Cscript Exam.vbs on the command line: CScript Exam.vbs
Use the redirector to run the script run the result to the text file: cscript exam.vbs> Output.txt // Cover Cscript Exam.vbs >> Output.txt // Reserved Add method
Use filesystemobject output to a file: Set objFS = CreateObject ( "Scripting.FileSystemObject") Set objNewFile = objFS.CreateTextFile ( "output.txt") objNewFile.WriteLine "Header Information - Date:" & Now () objNewFile.Close
Script Host Script Host: WScript.exe Based on GUI Window CScript.exe Based on Console Command Console