Yeah, this is pretty much out of my league. Shawn or Chris can you guys confirm?
On another note, got this from the SDK. There seems to be many other ways to call methods. But, like I said, this is trial and error for me with little logic and less understanding of why. Tell me if you can see anything in here worth following up on.
Code:
'*******************************************************************
' Name : CreateShare.vbs
'
' Purpose : This example creates a new share and sets the
' security descriptor for the new share.
'********************************************************************
'*** Connect to WMI and set security settings. ******
'*** You should substitute the name of the remote system for "\\myserver" ***
Set objservices = GetObject("WINMGMTS:" _
& "{impersonationLevel=impersonate,(Security)}" _
& "!\\myserver\ROOT\CIMV2")
'*** Get the Win32_SecurityDescriptor class and spawn a new instance ****
Set objclass = objservices.Get("Win32_SecurityDescriptor")
Set objSecDescriptor = objclass.SpawnInstance_()
'****** Prepare the security descriptor for the new share ******
objSecDescriptor.Properties_.Item("ControlFlags") = 4
Set ACE1 = SetACE(objservices, 2032127, _
3, _
0, _
SetTrustee(objservices, "myserver", _
"user1", _
Array(1, 5, 0, 0, 0, 0, 0, 5, 21, _
0, 0, 0, 160, 101, 207, 126, _
120, 75, 155, 95, 231, 124, _
135, 112, 119, 238, 0, 0)))
Set ACE2 = SetACE(objservices, 2032127, _
3, _
0, _
SetTrustee(objservices, Null, _
"EVERYONE", _
Array(1, 1, 0, 0, 0, 0, 0, 1, 0, _
0, 0, 0)))
objSecDescriptor.Properties_.Item("DACL") = Array(ACE1, ACE2)
'************************ Create the new share *********************
Set objShare = objservices.Get("Win32_Share")
Set objInParam = objShare.Methods_("Create").InParameters.SpawnInstance_()
objInParam.Properties_.Item("Access") = objSecDescriptor
objInParam.Properties_.Item("Description") = "New share created by WMI script"
objInParam.Properties_.Item("Name") = "NewShare"
objInParam.Properties_.Item("Path") = "C:\temp"
objInParam.Properties_.Item("Type") = 0
'objInParam.Properties_.item("MaximumAllowed") = 10 'optional - default is 'max allowed'
'objInParam.Properties_.item("Password") = "Password" 'optional - default is no password
'************************ Execute the method **********************
Set objOutParams = objShare.ExecMethod_("Create", objInParam)
If objOutParams.ReturnValue = 0 Then
wscript.echo "Share created successfully"
Else
If objOutParams.ReturnValue = 22 Then
wscript.echo "Share may already exist"
Else
wscript.echo "Unable to create share, return value was : " _
& objOutParams.ReturnValue
End If
End If
'************************* HELPER FUNCTIONS *********************
Function SetTrustee(objservices, strDomain, strName, SID)
Set objTrustee = objservices.Get("Win32_Trustee").SpawnInstance_
objTrustee.Domain = strDomain
objTrustee.Name = strName
objTrustee.Properties_.Item("SID") = SID
Set SetTrustee = objTrustee
End Function
Function SetACE(objservices, AccessMask, AceFlags, AceType, objTrustee)
Set objAce = objservices.Get("Win32_Ace").SpawnInstance_
objAce.Properties_.Item("AccessMask") = AccessMask
objAce.Properties_.Item("AceFlags") = AceFlags
objAce.Properties_.Item("AceType") = AceType
objAce.Properties_.Item("Trustee") = objTrustee
Set SetACE = objAce
End Function
'******************************************************************