Windows Management Scripting Learning _vbs

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.