Hi!
I am using this functions for sharing folder:
Protected Sub CreateShare(ByVal path As String, ByVal shareName As String)
' Create a ManagementClass object
Dim managementClass As New ManagementClass("Win32_Share")
' Create ManagementBaseObjects for in and out parameters
Dim inParams As ManagementBaseObject = managementClass.GetMethodParameters("Create")
Dim outParams As ManagementBaseObject
' Set the input parameters
inParams("Description") = "IdeaServer"
inParams("Name") = shareName
inParams("Path") = path
inParams("Type") = &H0
'Disk Drive
'Another Type:
' DISK_DRIVE = 0x0
' PRINT_QUEUE = 0x1
' DEVICE = 0x2
' IPC = 0x3
' DISK_DRIVE_ADMIN = 0x80000000
' PRINT_QUEUE_ADMIN = 0x80000001
' DEVICE_ADMIN = 0x80000002
' IPC_ADMIN = 0x8000003
'inParams["MaximumAllowed"] = int maxConnectionsNum;
' Invoke the method on the ManagementClass object
inParams("Access") = SecurityDescriptor1()
outParams = managementClass.InvokeMethod("Create", inParams, Nothing)
' Check to see if the method invocation was successful
Dim rVal As UInteger = DirectCast((outParams.Properties("ReturnValue").Value), UInteger)
If rVal <> 0 AndAlso rVal <> 22 Then
' ok if it already exists
Throw New Exception("Unable to share directory.")
End If
End Sub
Private Shared Function SecurityDescriptor1() As ManagementBaseObject
Dim account As New NTAccount("NT Authority", "Everyone")
Dim sid As SecurityIdentifier = DirectCast(account.Translate(GetType(SecurityIdentifier)), SecurityIdentifier)
Dim sidArray As Byte() = New Byte(sid.BinaryLength) {}
sid.GetBinaryForm(sidArray, 0)
Dim Trustee As ManagementObject = New ManagementClass(New ManagementPath("Win32_Trustee"), Nothing)
Trustee("Domain") = "Domain"
Trustee("Name") = "Name"
Trustee("SID") = sidArray
Dim AdminACE As ManagementObject = New ManagementClass(New ManagementPath("Win32_Ace"), Nothing)
AdminACE("AccessMask") = 2032127
AdminACE("AceFlags") = 3
AdminACE("AceType") = 1
AdminACE("Trustee") = Trustee
Dim SecurityDescriptor As ManagementObject = New ManagementClass(New ManagementPath("Win32_SecurityDescriptor"), Nothing)
SecurityDescriptor("ControlFlags") = 4
'SE_DACL_PRESENT
SecurityDescriptor("DACL") = New Object() {AdminACE}
Return SecurityDescriptor
End Function
Now what I want is to set password to this shared folder, that only user that know password can open this folder? How can I do that?
Thanks!