Creating Additional Objects

上一篇 / 下一篇  2010-03-23 23:19:04 / 个人分类:VBScript

We create thewshShellobject by using the following command:

Set bjShell = createObject("wscript.shell")

 

Once we create the wscript.shell object, we have access to the following methods:

Method

Purpose

Run

Runs an external command

Exec

Runs an external command, but provides access to the datastream

appActivate

Brings a specified window to the foreground

sendKeys

Enables you to send keystrokes to the foreground application

CreateShortCut

Creates shortcuts

LogEvent

Writes to the application Event log

RegRead

Reads from the registry

RegWrite

Writes to the registry

RegDelete

Deletes from the registry

PopUp

Displays a pop-up dialog box

ExpandEnvironmentStrings

Parses environmental variables (these variables can be displayed by using the Set command from a CMD prompt)

 

 

CreateAddRemoveShortCut.vbs

Option Explicit
Dim objShell
Dim strDesktop'pointer to desktop special folder
Dim objShortCut'used to set properties of the shortcut. Comes from using createShortCut
Dim strTarget
strTarget = "control.exe"
set bjShell = CreateObject("WScript.Shell")
strDesktop = objShell.SpecialFolders("Desktop")
 
set bjShortCut = objShell.CreateShortcut(strDesktop & "\AddRemove.lnk")
objShortCut.TargetPath = strTarget
objShortCut.Arguments = "appwiz.cpl"
objShortCut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,21"
objShortCut.description = "addRemove"
objShortCut.Save

 

 

 

 

RunNetStat.vbs

Option Explicit'is used to force the scripter to declare variables
'On Error Resume Next'is used to tell vbscript. to go to the next line if it encounters anError
Dim objShell'holds WshShell object
Dim objExecObject'holds what comes back from executing the command
Dim strText'holds the text stream from the exec command.
Dim command'the command to run 
command = "cmd /c netstat -ano"
WScript.Echo "starting program " & Now 'used to mark when program begins
Set bjShell = CreateObject("WScript.Shell")
Set bjExecObject = objShell.Exec(command)
 
Do Until objExecObject.StdOut.AtEndOfStream
 strText = objExecObject.StdOut.ReadAll()
 WScript.Echo strText
Loop
WScript.echo "complete" 'lets me know program is done running

 

 

 

 

From
Microsoft® VBScript. Step by Step
By Ed Wilson

 

 

 



TAG:

 

评分:0

我来说两句

Open Toolbar