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_Shar e")
Dim mo As ManagementObjec t
Dim inParams As ManagementBaseO bject
Dim outParams As ManagementBaseO bject
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
inParams = mc.GetMethodPar ameters("Create ")
inParams("Name" ) = "Temp"
inParams("Descr iption") = "Share"
inParams("Path" ) = Text1.Text
inParams("Type" ) = 0
outParams = mc.InvokeMethod ("Create", inParams, Nothing)
If Convert.ToInt32 (outParams.Prop erties("ReturnV alue").Value) = 0
Then
MessageBox.Show ("Successfully" )
End If
End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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.Prop erties("ReturnV alue").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_SecurityD escriptor.
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 2 5492
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.Prop erties("ReturnV alue").Value) = 0 Then
MessageBox.Show ("Successfully" )
Else
MessageBox.Show (Convert.ToInt3 2(outParams.Pro perties("Return Value").Value))
End If
"yxq" <ga***@163.ne t> wrote in message
news:%2******** ********@tk2msf tngp13.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_Shar e") Dim mo As ManagementObjec t Dim inParams As ManagementBaseO bject Dim outParams As ManagementBaseO bject
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click inParams = mc.GetMethodPar ameters("Create ")
inParams("Name" ) = "Temp" inParams("Descr iption") = "Share" inParams("Path" ) = Text1.Text inParams("Type" ) = 0
outParams = mc.InvokeMethod ("Create", inParams, Nothing)
If Convert.ToInt32 (outParams.Prop erties("ReturnV alue").Value) = 0 Then MessageBox.Show ("Successfully" ) End If End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) 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.Prop erties("ReturnV alue").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_SecurityD escriptor. 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
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.Reflecti on Master "
==== Converting to 2002 ====
Remove inline declarations
"yxq" <ga***@163.ne t> wrote in message
news:#x******** ******@tk2msftn gp13.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_Shar e") Dim mo As ManagementObjec t Dim inParams As ManagementBaseO bject Dim outParams As ManagementBaseO bject
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click inParams = mc.GetMethodPar ameters("Create ")
inParams("Name" ) = "Temp" inParams("Descr iption") = "Share" inParams("Path" ) = Text1.Text inParams("Type" ) = 0
outParams = mc.InvokeMethod ("Create", inParams, Nothing)
If Convert.ToInt32 (outParams.Prop erties("ReturnV alue").Value) = 0 Then MessageBox.Show ("Successfully" ) End If End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) 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.Prop erties("ReturnV alue").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_SecurityD escriptor. 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 want my users to be able to select a report, click on a command
button on a form, which will then automatically create the report as a
pdf file and save it to the user's machine.
I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
|
by: pnp |
last post by:
Hi all,
How can I make a folder shared from a pc through C# code?
Thanks in advance,
Peter
|
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 successfully create a new
FTP Server and virtual directory. The strange this is that the description
of the new server is (Stopped) and the status has the following warning "The
specified metadata was not found.". If I manually Stop the...
|
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 create files in sub directories withe the same name.
for example if I hace default.aspx created in my root directory and then I
want to create a new webform called default.aspx in a directory called
|
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 have worked in my
case so far. I'd appreciate any help anyone can offer!
Here's the problem:
When attempting to create a new ASP.NET Web project on my *local*
| |
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 folder on the Web server
containing an ASP.NET application.
I get a "Failed to start monitoring changes" when I try to run the
application. If I try to debug, I get a message "unable to start debugging
on the Web server".
I put an...
|
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 to create a hidden share, from
vb.net, for an existing folder on a remote server? e.g. for a folder
\\server2\D$\foldera\folderb\123456 I want to create a share on server2
\\server2\123456$ and give user 123456 full control of that folder.
...
|
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)
I installed FrontPage server extensions to IIS on my computer while
following instructions in a Microsoft ASP.Net MCSD training book.
After installing the FrontPage Server Extensions I cannot create a new
|
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 "/website1" in the path? I want the URL to be
http://localhost:49299/default.aspx
The reason I want to get rid of /website1 is that I want the URL to be
http://www.mycompany.com/default.aspx on production machine.
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |