This article is recommended by Webmaster (reterry) Article A friend who wants to learn VBScript, I suggest you go to the official website of Microsoft to check out what is good and humorous. I used to read vbscirpt and read many things, you may not be able to understand it at the beginning, but don't be discouraged. It feels good. You can copy it in your book to make it better. Then download a vbscirpt help file, which is available at Microsoft, then let's take a look at multiple exercises.
It took me half a day to read "script Story" in MS technet. The article was very humorous. It would be nice if all the technical articles were written in this easy way.
WMI -- Windows Management Instrumentation
Related links:
Microsoft Script 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: displays the total memory of the Local Machine
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 ob1_miservice = 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 = obw.miservice. execnotificationquery (strwql)
Set objeventobject = objeventsource. nextevent ()
Wscript. Echo "A new instance of notepad was just started ."
Use shell in the script)Program
Set objshell = wscript. Createobject ("wscript. Shell ")
Objshell. Run "Notepad" 'Run notepad
Call the command program (‑comspec=environment variable call the cmd.exe or command.exe of the corresponding operating system) to run the script and keep the console window:
Set objshell = Createobject ("wscript. Shell ")
Objshell. Run "% comspec %/K ipconfig"
Instead of the run method, you can use the exec method of objshell to return a wshscriptexec object for running the command. You can control the result display more.
Run the script exam. vbs:
Enter cscript exam. vbs in the command line.
Use the redirection to output the script running result to a text file:
Cscript exam. vbs> output.txt // overwrite Mode
Cscript exam. vbs> output.txt // retain the Add Method
Output to a file using FileSystemObject:
Set objfs = Createobject ("scripting. FileSystemObject ")
Set objnewfile = objfs. createtextfile ("output.txt ")
Objnewfile. writeline "header information -- Date:" & now ()
Objnewfile. Close
Script Host:
Wscript.exe Gui-based window
Cscript.exe Console