The following walkthrough describes how a typical Network Administrator or other IT professional might use WSH 5.6 to create procedures that accomplish useful tasks.
Note The walkthrough is presented in VBScript. The process for creating these scripts is nearly the same for developers using VBScript or JScript.
During the course of this walkthrough, you will perform the following activities:
To complete the walkthrough, all remote machines must be properly configured to enable Remote WSH. For more information on enabling these security settings, see Setting up Remote WSH.
Note The following code is from the sample included in this documentation. To view the entire sample, see WSH Network Administrator Sample Script.
To create the necessary variables and constants
Dim FSO Dim Services Dim SecDescClass Dim SecDesc Dim Trustee Dim ACE Dim Share Dim InParam Dim Network
Const FolderName = "C:\Public" Const AdminServer = "\\AdminMachine" Const ShareName = "Pubs" Const PrinterShare = "\\CorpPrinters\PrinterShare"
To connect the machine to a common printing device
Set Network = CreateObject("Wscript.Network") Network.AddWindowsPrinterConnection PrinterShare
To set the machines default printing device
Network.SetDefaultPrinter PrinterShare
To create a common share on the machine
Set FSO = CreateObject("Scripting.FileSystemObject") If Not FSO.FolderExists(FolderName) Then FSO.CreateFolder(FolderName) End If
To copy files to the newly created folder
Call FSO.CopyFile(AdminServer & "\Public\Images\*.*", FolderName)
To establish the newly created folder as a share with WMI
Note WMI is a powerful, sophisticated technology based on Web Based Enterprise Management (WBEM). WMI is primarily used for accessing and instrumenting management information in an enterprise environment. For more information on WMI, see Microsoft Windows Management Instrumentation: Background and Overview at (http://msdn.microsoft.com/library/default.asp?URL=/library/backgrnd/html/wmixwdm.htm).
Set Services = GetObject("WINMGMTS:{impersonationLevel=impersonate,(Security)}!" & AdminServer & "\ROOT\CIMV2") Set SecDescClass = Services.Get("Win32_SecurityDescriptor") Set SecDesc = SecDescClass.SpawnInstance_() Set Trustee = Services.Get("Win32_Trustee").SpawnInstance_ Trustee.Domain = Null Trustee.Name = "EVERYONE" Trustee.Properties_.Item("SID") = Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0) Set ACE = Services.Get("Win32_Ace").SpawnInstance_ ACE.Properties_.Item("AccessMask") = 2032127 ACE.Properties_.Item("AceFlags") = 3 ACE.Properties_.Item("AceType") = 0 ACE.Properties_.Item("Trustee") = Trustee SecDesc.Properties_.Item("DACL") = Array(ACE) Set Share = Services.Get("Win32_Share") Set InParam = Share.Methods_("Create").InParameters.SpawnInstance_() InParam.Properties_.Item("Access") = SecDesc InParam.Properties_.Item("Description") = "Public Share" InParam.Properties_.Item("Name") = ShareName InParam.Properties_.Item("Path") = FolderName InParam.Properties_.Item("Type") = 0 Share.ExecMethod_("Create", InParam)
The sample included in this documentation contains a complete, executable script with all of the functionality above. See WSH Network Administrator Sample Script.
Before running the script, ensure that all remote machines have been properly configured to run remote scripts. This is accomplished with Poledit.exe on the server. For more information, see Setting up Remote WSH.
When running remote WSH, the script is copied to the remote machines. Once the remote machine's security settings have been verified and the script is successfully copied, a return indicates success or failure. If successful, the script is then executed on the remote machines. For more information on running a remote WSH script, see Running Scripts Remotely.
Setting up Remote WSH | Accessing Networks | Running Scripts Remotely