0% found this document useful (0 votes)
91 views

Option Explicit: "C:/Public" "//adminmachine" "Pubs" "//Corpprinters/Printershare"

This document contains a script that uses WMI to perform common administrative tasks on remote machines, including adding a default printer, creating a shared folder, populating it with files, and setting permissions to allow public access. It creates a public folder on the remote machine, copies files to it, and then shares the folder out on the network for public access using WMI calls.

Uploaded by

radutari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Option Explicit: "C:/Public" "//adminmachine" "Pubs" "//Corpprinters/Printershare"

This document contains a script that uses WMI to perform common administrative tasks on remote machines, including adding a default printer, creating a shared folder, populating it with files, and setting permissions to allow public access. It creates a public folder on the remote machine, copies files to it, and then shares the folder out on the network for public access using WMI calls.

Uploaded by

radutari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

D:\Codigo Fuente\Windows Scripting Hosting\AdminScript.

vbs

mircoles, 15 de junio de 2016 09:54 a.m.

'
'
'
'
'
'
'

Remote WSH Admin Sample

AdminScript.vbs

'
'
'
'

Note that in the interests of keeping this example code small, error
handling has been omitted. Actual production code should use
appropriate error handling as many of these operations could fail;
the disks could run out of space, for instance.

This sample code does a few common administrative tasks which a


network administrator might want to do to a number of the machines
on his or her network: it creates a public directory, populates
it with some files and shares the directory out. It also sets
up the machines default printer connection.

Option Explicit
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim

FSO
Services
SecDescClass
SecDesc
Trustee
ACE
Share
InParam
Network

Const
Const
Const
Const

FolderName = "C:\Public"
AdminServer = "\\AdminMachine"
ShareName = "Pubs"
PrinterShare = "\\CorpPrinters\PrinterShare"

' First we add a printer to this machine and make it the default.
Set Network = CreateObject("Wscript.Network")
Network.AddWindowsPrinterConnection PrinterShare
Network.SetDefaultPrinter PrinterShare
' Next we create a folder and populate it with some files.
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(FolderName) Then
FSO.CreateFolder(FolderName)
End If
Call FSO.CopyFile(AdminServer & "\Public\Images\*.*", FolderName)
' Make the folder into a share using WMI
' See the WMI SDK for information on how this code works.
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_
-1-

D:\Codigo Fuente\Windows Scripting Hosting\AdminScript.vbs

mircoles, 15 de junio de 2016 09:54 a.m.

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)
' And we're done.

-2-

You might also like