Webmaster (reterry) Recommended this article, want to learn VBScript friend, I suggest to Microsoft's official website to see, where things are very good, vivid humor, I used to learn vbscirpt often go there to see, and a lot of things, not necessarily just start to see understand, but don't lose heart, To feel good, you can use the book copy, learning effect will be better, and then download a vbscirpt Help file, Microsoft Some, and then see more practice.
It took half a day to see the story of the script in Ms TechNet, and the article was very lively and humorous, if all the technical articles were written in such a relaxed way.
WMI-Windows Management Instrumentation
RELATED links:
Microsoft Scripting Guide: http://www.microsoft.com/china/technet/community/columns/scripts/default.mspx
MSDN WMI Scripting primer:http://www.microsoft.com/china/technet/archives/columns/scripts/sg0103.asp
Script Example 1, showing total native 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.totalphysicalmemory
Next
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."
Using shell (shell) programs in scripts
Set Objshell = WScript.CreateObject ("Wscript.Shell")
Objshell.run "Notepad" Run Notepad
Invoke the command program (the%comspec% environment variable calls the appropriate operating system's Cmd.exe or Command.exe) to run the script and keep the console window:
Set Objshell = CreateObject ("Wscript.Shell")
Objshell.run "%comspec%/k ipconfig"
Using the Objshell Exec method instead of the Run method returns the run to a Wshscriptexec object, which shows more control over the results.
Run script Exam.vbs:
At the command line, enter: Cscript Exam.vbs
To output a script run results to a text file using the redirection character:
cscript exam.vbs > output.txt//Cover mode
cscript exam.vbs >> output.txt//Retention Add mode
Output to file using FileSystemObject:
Set objFS = CreateObject ("Scripting.FileSystemObject")
Set objnewfile = Objfs.createtextfile ("output.txt")
Objnewfile.writeline "Header Information-Date:" & Now ()
Objnewfile.close
Scripting Host script hosts:
Wscript.exe GUI-based windows
Cscript.exe based console Command console