Hi Jeff,
I am sorry if I have made any confusion.
Here goes the code. Please take a look at the comments in the code.
Basically we need to read the links below to achieve the job.
How to use the Win32_Share to create network share
Win32_Share
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_share.asp
Create Method of the Win32_Share Class
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
create_method_i n_class_win32_s hare.asp
How to set the security account
Win32_ACE
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_ace.asp
Win32_Trustee
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_trustee.a sp
How to locate a user account by ldap path
LDAP ADsPath
http://msdn.microsoft.com/library/de...us/adsi/adsi/l
dap_adspath.asp
<code>
Imports System.Manageme nt
Imports System.Director yServices
Module Module1
Sub Main()
Dim serverName, UserName, AdminName, UserAcct As String
Dim Ace1 As Management.Mana gementObject
serverName = "TestServer "
Dim scope As New
Management.Mana gementScope("\\ serverName\root \cimv2")
'Win32_Share
'http://msdn.microsoft. com/library/default.asp?url =/library/en-us/wmisdk/wmi
/win32_share.asp
Dim wmiShare As New Management.Mana gementClass(sco pe, New
Management.Mana gementPath("Win 32_Share"), Nothing)
'Define the LDAP path to the desired user account.
'LDAP ADsPath
'http://msdn.microsoft. com/library/default.asp?url =/library/en-us/adsi/adsi/
ldap_adspath.as p
UserAcct = "CN=Jeff Smith,CN=users, DC=fabrikam,DC= com"
'Get the user's information from the Active Directory
Dim UserNamePath As String = "LDAP://" & UserAcct
Dim DirEnt As New DirectoryServic es.DirectoryEnt ry(UserNamePath )
'Get the User's SID and samAccountname. It will be used when
creating the DACL
UserName = DirEnt.Properti es("samaccountn ame")(0)
Dim UserSID As Byte() = DirEnt.Properti es("objectsid") (0)
DirEnt.Dispose( )
'Set an ACE for the user
Ace1 = SetAce(scope, 2032127, 3, 0, SetTrustee(scop e, serverName,
UserName, UserSID))
'Place the aces into a Win32_SecurityD escriptor
Dim secDescriptor As Management.Mana gementObject
secDescriptor = New Management.Mana gementClass(sco pe, New
Management.Mana gementPath("Win 32_SecurityDesc riptor"),
Nothing).Create Instance()
secDescriptor(" ControlFlags") = 4
secDescriptor(" DACL") = New Management.Mana gementObject() {Ace1}
'Prepare to invoke the CREATE method on Win32_Share by specifying
the parameters
Dim inParams As Management.Mana gementBaseObjec t
inParams = wmiShare.GetMet hodParameters(" Create")
inParams("Acces s") = secDescriptor
inParams("Path" ) = "C:\TestFol der"
inParams("Name" ) = "TestFolder "
inParams("Type" ) = 0
inParams("Descr iption") = "FolderDescript ionHere"
Dim outParams As Management.Mana gementBaseObjec t
'Invoke the CREATE method and create the share.
'Create Method of the Win32_Share Class
'http://msdn.microsoft. com/library/default.asp?url =/library/en-us/wmisdk/wmi
/create_method_i n_class_win32_s hare.asp
outParams = wmiShare.Invoke Method("Create" , inParams, Nothing)
End Sub
Function SetTrustee(ByVa l scope As Management.Mana gementScope, ByVal
domain As String, ByVal name As String, ByVal UserSid As Byte()) As
Management.Mana gementObject
Dim wmiTrustee As Management.Mana gementObject
'Win32_Trustee
'http://msdn.microsoft. com/library/default.asp?url =/library/en-us/wmisdk/wmi
/win32_trustee.a sp
wmiTrustee = New Management.Mana gementClass(sco pe, New
Management.Mana gementPath("Win 32_Trustee"), Nothing).Create Instance()
wmiTrustee("Dom ain") = domain
wmiTrustee("Nam e") = name
wmiTrustee("SID ") = UserSid
Return wmiTrustee
End Function
Function SetAce(ByVal scope As Management.Mana gementScope, ByVal
accessMask As Integer, ByVal aceFlags As Integer, ByVal aceType As Integer,
ByVal wmiTrustee As Management.Mana gementObject) As
Management.Mana gementObject
Dim wmiAce As Management.Mana gementObject
'Win32_ACE
'http://msdn.microsoft. com/library/default.asp?url =/library/en-us/wmisdk/wmi
/win32_ace.asp
wmiAce = New Management.Mana gementClass(sco pe, New
Management.Mana gementPath("Win 32_ACE"), Nothing).Create Instance()
wmiAce("AccessM ask") = accessMask
wmiAce("AceFlag s") = aceFlags
wmiAce("AceType ") = aceType
wmiAce("Trustee ") = wmiTrustee
Return wmiAce
End Function
End Module
</code>
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.