VBScript - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

VBScript

Description:

Title: VBScript Session 14 Subject: Advanced - Dictionary Object Author: Dani Vainstein Keywords: Dictionary Description: Dictionary object Method and properties – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 20
Provided by: DaniV151
Category:

less

Transcript and Presenter's Notes

Title: VBScript


1
VBScript
  • Session 18

2
What we learn last session?
3
Subjects for session 18
  • WshNetwork Object
  • Mapping a nwtwork printer.
  • Mapping a network drive.
  • WshShell Object
  • Environment Varibles.
  • Creating shorcuts.
  • Special folder.
  • Using the registry.
  • WMI

4
WshNetwork Object
  • Provides access to the shared resources on the
    network to which your computer is connected.
  • You create a WshNetwork object when you want to
    connect to network shares and network printers,
    disconnect from network shares and network
    printers, map or remove network shares, or access
    information about a user on the network.

5
WshNetwork Object
  • The following example demonstrates displaying the
    domain name, computer name, and user name for the
    current computer system using the WshNetwork
    object.
  • Set objWshNetwork CreateObject("WScript.Network
    ")
  • MsgBox "Domain " objWshNetwork.UserDomain
  • MsgBox "Computer Name " objWshNetwork.Compute
    rName
  • MsgBox "User Name " objWshNetwork.UserName

6
WshNetwork Object AddWindowsPrinterConnection
Method
  • Adds a Windows-based printer connection to your
    computer system.
  • Syntax
  • object.AddWindowsPrinterConnection(
    strPrinterPath )
  • Using this method is similar to using the Printer
    option on Control Panel to add a printer
    connection.
  • Unlike the AddPrinterConnection method, this
    method allows you to create a printer connection
    without directing it to a specific port, such as
    LPT1.
  • If the connection fails, an error is thrown.

7
WshNetwork Object MapNetworkDrive Method
  • Adds a shared network drive to your computer
    system.
  • Syntax
  • object.MapNetworkDrive(strLocalName,
    strRemoteName, bUpdateProfile, strUser,
    strPassword)
  • An attempt to map a non-shared network drive
    results in an error.

8
WshShell Object
  • You create a WshShell object whenever you want to
    run a program locally, manipulate the contents of
    the registry, create a shortcut, or access a
    system folder.
  • The WshShell object provides the Environment
    collection.
  • This collection allows you to handle
    environmental variables (such as WINDIR, PATH, or
    PROMPT).

9
WshShell ObjectCreateShortcut Method
  • Creates a new shortcut, or opens an existing
    shortcut.
  • Syntax
  • object.CreateShortcut(strPathname)
  • The CreateShortcut method returns either a
    WshShortcut object or a WshURLShortcut object.
  • Simply calling the CreateShortcut method does not
    result in the creation of a shortcut.
  • The shortcut object and changes you may have made
    to it are stored in memory until you save it to
    disk with the Save method.

10
WshShell ObjectSpecial Folders Property
  • Returns a SpecialFolders object (a collection of
    special folders).
  • Syntax
  • object.SpecialFolders(objWshSpecialFolders)
  • The WshSpecialFolders object is a collection.
  • It contains the entire set of Windows special
    folders, such as the Desktop folder, the Start
    Menu folder, and the Personal Documents folder.
  • The special folder name is used to index into the
    collection to retrieve the special folder you
    want.
  • The SpecialFolders property returns an empty
    string if the requested folder (strFolderName) is
    not available.

11
WshShell ObjectSpecial Folders Property
  • The following special folders are available
  • AllUsersDesktop
  • AllUsersStartMenu
  • AllUsersPrograms
  • AllUsersStartup
  • Desktop
  • Favorites
  • Fonts
  • MyDocuments
  • NetHood
  • PrintHood
  • Programs
  • Recent
  • SendTo
  • StartMenu
  • Startup
  • Templates

12
WshShell ObjectUsing the Registry
  • RegRead method.
  • Returns the value of a key or value-name from the
    registry.
  • RegDelete method.
  • Deletes a key or one of its values from the
    registry.
  • RegWrite method
  • Creates a new key, adds another value-name to an
    existing key (and assigns it a value), or changes
    the value of an existing value-name.

13
WshShell ObjectRegistry Abbreviations
HKCU HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
HKCR HKEY_CLASSES_ROOT
HKEY_USERS HKEY_USERS
HKEY_CURRENT_CONFIG HKEY_CURRENT_CONFIG
Abbreviation Root key Name
HKCU HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
HKCR HKEY_CLASSES_ROOT
HKEY_USERS HKEY_USERS
HKEY_CURRENT_CONFIG HKEY_CURRENT_CONFIG
14
WMIWindows Management Instrumentation
  • Windows Management Instrumentation (WMI) is a
    component of the Microsoft Windows operating
    system and is the Microsoft implementation of
    Web-Based Enterprise Management (WBEM), which is
    an industry initiative to develop a standard
    technology for accessing management information
    in an enterprise environment.
  • WMI uses the Common Information Model (CIM)
    industry standard to represent systems,
    applications, networks, devices, and other
    managed components.
  • You can use WMI to automate administrative tasks
    in an enterprise environment.
  • WMI can be used in all Windows-based
    applications, and is most useful in enterprise
    applications.

15
WMIWMI Classes
  • Microsoft Windows classes give you the means to
    manipulate a variety of objects. The following
    identifies the categories of Windows classes.
  • Computer system hardware - Classes that represent
    hardware related objects.
  • Operating System - Classes that represent
    operating system related objects.
  • Installed Applications - Classes that represent
    software related objects.
  • WMI Services ?Management - Classes used to manage
    WMI.
  • Performance Counters - Classes that represent
    formatted and raw performance data.

16
WMIWin32_OperatingSystem Class
  • The Win32_OperatingSystem WMI class represents an
    operating system installed on a Windows computer
    system.
  • Any operating system that can be installed on a
    Windows system is a descendent or member of this
    class.
  • If a computer has multiple operating systems
    installed, this class returns only an instance
    for the currently active operating system.

17
WMIWin32_OperatingSystem Class
  • Methods
  • Reboot
  • ShutDown
  • SetDateTime
  • Win32_Shutdown
  • For more informationhttp//msdn.microsoft.com/lib
    rary/default.asp?url/library/en-us/wmisdk/wmi/win
    32_operatingsystem.asp

18
WMIExample
  • Const WMI_REBOOT 2
  • strComputer "."
  • Set objWMIService GetObject("winmgmts\\"
    strComputer "\root\cimv2")
  • Set colItems objWMIService.ExecQuery("Select
    from Win32_OperatingSystem",,48)
  • For Each objItem in colItems
  • MsgBox "LastBootUpTime " objItem.LastBootUpTim
    e
  • MsgBox "FreePhysicalMemory "
    objItem.FreePhysicalMemory
  • objWMIService.ExecMethod objItem , ShutDown"
  • objItem.Win32Shutdown(WMI_REBOOT)
  • Next

19
Make sure to visit us
  • Tutorials
  • Articles
  • Projects
  • And much more
  • www.AdvancedQTP.com
Write a Comment
User Comments (0)
About PowerShow.com