473,416 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Why can not create the share of root directory ?

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
2 5466
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
4
by: pnp | last post by:
Hi all, How can I make a folder shared from a pc through C# code? Thanks in advance, Peter
0
by: No Spam | last post by:
After looking all the ways to progrrammatically create a new FTP Server & Virtual Directory, I have come to see that the code below is the cleanest. Here is my basic issue. When I run this code, I...
3
by: martin | last post by:
Hi, this is going to sound amazingly stupid but I have to ask. whenever I create a new webform in visual studio, it always wants to save the form in the root directory. This makes it hard to...
0
by: Mr. Land | last post by:
Hello. I'm having trouble creating a new Web project using VS .NET 2003 on the local default web. I've done a lot of research about this and found a lot of suggestions, but none of them seem to...
8
by: JR | last post by:
I have a Web server running on Windows XP. On this Web server, I have a Web site configured with its home directory on a network share. In the Web site, there's a virtual folder pointing to a local...
2
by: freenews.netfront.net | last post by:
Hi, I am writing an asp.net / Active Directory application using vb.net in it's code-behind pages. The app is running on the W2k3 (r1) domain controller (e.g. server1). Does anyone know how...
6
by: JonSteng | last post by:
..Net Visual Studio Professional 2003 Version 7.1.3088 ..Net Framework 1.1 SP1 Version 1.1.4322 IIS 5.1 Windows XP Professional SP2 Micron T3000 Laptop (1.5 GHz; 1GB RAM; 40GB HD with 17GB Free)...
3
by: ningjun.wang | last post by:
I use Visual Studio .NET 2005 to create a website called "website1". When I start this website in Visual Studio, the URL is http://localhost:49299/website1/default.aspx How can I get rid of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.