By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,574 Members | 2,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,574 IT Pros & Developers. It's quick & easy.

Why can not create the share of root directory ?

P: n/a
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


Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Perhaps because the root folders are typically already shared as hidden
admin shares (e.g. \\server\c$ )

What is the return code when it fails?

If Convert.ToInt32(outParams.Properties("ReturnValue" ).Value) = 0 Then
MessageBox.Show("Successfully")
Else

MessageBox.Show(Convert.ToInt32(outParams.Properti es("ReturnValue").Value))
End If

"yxq" <ga***@163.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #2

P: n/a
Hi yxq,

In a NT environment... NT4, 2000, 2003, XP, the root directories are shared
for administrative purposes as <driveletter>$, etc. You cannot remove, nor
change permissions, on these shares as they are managed by Windows itself.

You can, however, share the drive again as a different name, i.e. C$ points
to C:\ and Drive_C also points to C:\, then you can remove Drive_C, but you
cannot remove the Administrative shares.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations

"yxq" <ga***@163.net> wrote in message
news:#x**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.