A VBScript18

Share Embed Donate


Short Description

Download A VBScript18...

Description

VBScript Session 18

?What we learn last session

Subjects for session 18 

WshNetwork Object  



WshShell Object    



Mapping a nwtwork printer. Mapping a network drive.

Environment Varibles. Creating shorcuts. Special folder. Using the registry.

WMI

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.

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.ComputerName MsgBox "User Name = " & objWshNetwork.UserName

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.

WshNetwork Object MapNetworkDrive Method 



Adds a shared network drive to your computer system. Syntax 



object .MapNetworkDrive(strLocalNa me, me, strRemoteName, strRemoteName, [bUpdateProfile [bUpdateProfile], ], [strUser ], ], [strPassword  [strPassword ]) ])

An attempt to map a non-shared network drive results in an error.

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 environmental variables (such as WINDIR, PATH, or PROMPT).

WshShell Object CreateShortcut Method  

Creates a new shortcut, or opens an existing shortcut. Syntax 







object .CreateShortcut (strPathname) 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.

WshShell Object Special 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 collection to retrieve the special folder you want. The SpecialFolders property returns an empty string if the requested folder (strFolderName (strFolderName)) is not available.

WshShell Object Special Folders Property 

The following special folders are available:                

AllUsersDesktop AllUsersStartMenu AllUsersPrograms AllUsersStartup Desktop Favorites Fonts MyDocuments NetHood PrintHood Programs Recent SendTo StartMenu Startup Templates

WshShell Object Using the Registry 

RegRead method. 



RegDelete method. 



Returns the value of a key or value-name from the registry. 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.

WshShell Object Registry Abbreviations Root key Name

Abbreviation

HKEY_CURRENT_USER

HKCU

HKEY_LOCAL_MACHINE

HKLM

HKEY_CLASSES_ROOT

HKCR

HKEY_USERS

HKEY_USERS

HKEY_CURRENT_CONFIG HKEY_CURRENT_CONFIG HKEY_CURRENT_CONFIG

WMI Windows Management Instrumentation 







Windows® Management Instrumentation (WMI) is a component of the Microsoft® Windows® operating system and is the Microsoft M icrosoft 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 i n an enterprise environment. WMI can be used in all Windows-based applications, and is most useful in enterprise applications.

WMI WMI 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 re present software related objects. WMI Services ?Management - Classes used to manage WMI. Performance Counters - Classes that represent formatted and raw performance data.

WMI Win32_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.

WMI Win32_OperatingSystem Class 

Methods Reboot  ShutDown  SetDateTime  Win32_Shutdown 



For more information http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_o

WMI Example

Const WMI_REBOOT = 2 strComputer = "." Set objWMIService objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery(" objWMIService.ExecQuery("Select Select * from Win32_OperatingSystem",,48) Win32_OperatingSystem",,48) For Each objItem in colItems MsgBox "LastBootUpTime: " & objItem.LastBootUpTime MsgBox "FreePhysicalMemory: " & objItem.FreePhysicalMemory objWMIService.ExecMetho objWMIService.ExecMethod d objItem , “ShutDown" objItem.Win32Shutdown( objItem.Win32Shutdown(WMI_REBOOT) WMI_REBOOT) Next

Make sure to visit us    

Tutorials Articles Projects And much more www.AdvancedQTP.com

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF