Scripting in Visual Basic
If you choose to start writing your script as a Visual Basic program, use the following procedure.
To create a Visual Basic program for SMS operations
Start Visual Basic, and then create a new project.
On the Project menu, click References, and then click Microsoft WMI Scripting Vx.x Library.
In the "(General)", "(Declarations)" section of your program, add
Private WbemServices as SWbemServices.
In a new subroutine (or function), add
Dim loc as New SWbemLocator.
Set WbemServices = loc.ConnectServer( , "root\SMS\site_<site code>")(add the server name as the first parameter and the user name and password as the third and fourth parameters (if necessary) if the script will run from a computer other than the site server).
Wherever you need variables for the WMI objects, include
Dim <variable name> as SWbemObject(or
The Visual Basic program is now ready to work with WMI, and thus with SMS objects. Examples from this appendix can be used in the program (except that the lines to create a locator and connect to the WMI server do not have to be included).
If you are going to take advantage of Wscript classes (such as (like Wscript.Network or Wscript.Shell) in your scripts, add a reference for Windows Script Host Object Model and use it like the locator (for example,
Dim X as New IWshNetwork_Class).
If you created the program in Visual Basic and want to translate it to VBScript (so that it can be used wherever scripts are used), use the following procedure.
To translate scripts developed as Visual Basic programs to VBScript
Copy the subroutines from Visual Basic.
Change the line from step 4 in the previous procedure to
The line that was added in step 5 of the previous procedure stays the same.
Change lines that were added in step 6 to
Dim <name>(and do not specify a data type).
Where appropriate, translate any logic that outputs values (by adding them to list boxes, for example) to use Wscript.Echo instead.
Where appropriate, add lines to create any objects that your Visual Basic program references, such as:
Dim x As WshNetwork Set x = New WshNetwork
Must be changed to:
For More Information
Did you find this information useful? Please send your suggestions and comments about the documentation to firstname.lastname@example.org.