Option Explicit: "C:/Public" "//adminmachine" "Pubs" "//Corpprinters/Printershare"
Option Explicit: "C:/Public" "//adminmachine" "Pubs" "//Corpprinters/Printershare"
vbs
'
'
'
'
'
'
'
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.
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-
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-