Y
yxq
Hello
I want to create and delete the folder share, i found that it is ok for
generic folder, but it does not work for Root directory(i.e c:\, d:\)
The code
****************************************************
Dim mc As New ManagementClass("Win32_Share")
Dim mo As ManagementObject
Dim inParams As ManagementBaseObject
Dim outParams As ManagementBaseObject
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
inParams = mc.GetMethodParameters("Create")
inParams("Name") = "Temp"
inParams("Description") = "Share"
inParams("Path") = Text1.Text
inParams("Type") = 0
outParams = mc.InvokeMethod("Create", inParams, Nothing)
If Convert.ToInt32(outParams.Properties("ReturnValue").Value) = 0
Then
MessageBox.Show("Successfully")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
For Each mo In mc.GetInstances()
If CType(mo("Path"), String) = Text1.Text Then
outParams = mo.InvokeMethod("Delete", Nothing, Nothing)
If
Convert.ToInt32(outParams.Properties("ReturnValue").Value) = 0 Then
MessageBox.Show("Deleted successfully")
End If
Exit For
End If
Next
End Sub
*****************************************************************
Parameters
Path
[in] Local path of the Windows share. For example, "C:\Program Files".
Name
[in] Passes the alias to a path set up as a share on a Windows system.
Example, "public".
Type
[in] Passes the type of resource being shared. Types includes disk drives,
print queues, interprocess communications (IPC), and general devices. Can be
one of the following values. Value Meaning
0
0x0 Disk Drive
1
0x1 Print Queue
2
0x2 Device
3
0x3 IPC
2147483648
0x80000000 Disk Drive Admin
2147483649
0x80000001 Print Queue Admin
2147483650
0x80000002 Device Admin
2147483651
0x80000003 IPC Admin
MaximumAllowed
[in] Limit on the maximum number of users allowed to concurrently use this
resource. Example: 10. This parameter is optional.
Description
[in] Optional comment to describe the resource being shared. This
parameter is optional.
Password
[in] Password (when the server is running with share-level security) for
the shared resource. If the server is running with user-level security, this
parameter is ignored. This parameter is optional.
Access
[in] Security descriptor for user level permissions. A security descriptor
contains information about the permissions, owner, and access capabilities
of the resource. For more information, see Win32_SecurityDescriptor.
Return Values
Returns one of the values in the following table or any other value to
indicate an error.
Return Code Description
0 Success
2 Access denied
8 Unknown failure
9 Invalid name
10 Invalid level
21 Invalid parameter
22 Duplicate share
23 Redirected path
24 Unknown device or directory
25 Net name not found
I want to create and delete the folder share, i found that it is ok for
generic folder, but it does not work for Root directory(i.e c:\, d:\)
The code
****************************************************
Dim mc As New ManagementClass("Win32_Share")
Dim mo As ManagementObject
Dim inParams As ManagementBaseObject
Dim outParams As ManagementBaseObject
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
inParams = mc.GetMethodParameters("Create")
inParams("Name") = "Temp"
inParams("Description") = "Share"
inParams("Path") = Text1.Text
inParams("Type") = 0
outParams = mc.InvokeMethod("Create", inParams, Nothing)
If Convert.ToInt32(outParams.Properties("ReturnValue").Value) = 0
Then
MessageBox.Show("Successfully")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
For Each mo In mc.GetInstances()
If CType(mo("Path"), String) = Text1.Text Then
outParams = mo.InvokeMethod("Delete", Nothing, Nothing)
If
Convert.ToInt32(outParams.Properties("ReturnValue").Value) = 0 Then
MessageBox.Show("Deleted successfully")
End If
Exit For
End If
Next
End Sub
*****************************************************************
Parameters
Path
[in] Local path of the Windows share. For example, "C:\Program Files".
Name
[in] Passes the alias to a path set up as a share on a Windows system.
Example, "public".
Type
[in] Passes the type of resource being shared. Types includes disk drives,
print queues, interprocess communications (IPC), and general devices. Can be
one of the following values. Value Meaning
0
0x0 Disk Drive
1
0x1 Print Queue
2
0x2 Device
3
0x3 IPC
2147483648
0x80000000 Disk Drive Admin
2147483649
0x80000001 Print Queue Admin
2147483650
0x80000002 Device Admin
2147483651
0x80000003 IPC Admin
MaximumAllowed
[in] Limit on the maximum number of users allowed to concurrently use this
resource. Example: 10. This parameter is optional.
Description
[in] Optional comment to describe the resource being shared. This
parameter is optional.
Password
[in] Password (when the server is running with share-level security) for
the shared resource. If the server is running with user-level security, this
parameter is ignored. This parameter is optional.
Access
[in] Security descriptor for user level permissions. A security descriptor
contains information about the permissions, owner, and access capabilities
of the resource. For more information, see Win32_SecurityDescriptor.
Return Values
Returns one of the values in the following table or any other value to
indicate an error.
Return Code Description
0 Success
2 Access denied
8 Unknown failure
9 Invalid name
10 Invalid level
21 Invalid parameter
22 Duplicate share
23 Redirected path
24 Unknown device or directory
25 Net name not found