Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / January 2004

Tip: Looking for answers? Try searching our database.

How to rename shares/directories

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeremy Chapman - 15 Jan 2004 00:59 GMT
Given a path, is it possible to programatically determine if that path is a
share, or an actuall directory?
Then, if it is a share, how do I rename it? and how do I determine what
directory it points to?
Chris Taylor - 17 Jan 2004 13:18 GMT
Hi,

To work with shares you can use the WNetXXX functions provided in mpr.dll.
Here is an example using WNetGetConnection to determine what resource a
share is mapped to.

 [DllImport("mpr.dll")]
 public extern static short WNetGetConnection(
   string lpLocalName,
   StringBuilder lpRemoteName,
   ref short lpnLength );

use it as follows

 StringBuilder sb = new StringBuilder(256);
 short len = 256;

 short err = WNetGetConnection( "Z:", sb, ref len );

If 'Z:' in this case is a network share, sb will contain the path (assuming
the sb is big enough), other wise you will get an error, take a look in
WinError.h for the error numbers. ERROR_NOT_CONNECTED (2250) will be
returned if 'Z:' does not map to a network resource.

You can use WNetCancelConnection to delete a network share and
WNetAddConnection/2/3 to add a new share.

Hope this helps

Signature

Chris Taylor
http://dotnetjunkies.com/WebLog/chris.taylor/

> Given a path, is it possible to programatically determine if that path is a
> share, or an actuall directory?
> Then, if it is a share, how do I rename it? and how do I determine what
> directory it points to?
Michael Bray - 22 Jan 2004 23:38 GMT
> To work with shares you can use the WNetXXX functions provided in
> mpr.dll. Here is an example using WNetGetConnection to determine what
> resource a share is mapped to.

You can also enumerate the items returned by WMI's Win32_Share container.  
This eliminates the need to do your own PInvoke (I would think that
System.Management WMI functions are just wrappers, but either way WMI is a
nice way to get this info.)

-mdb
Chris Taylor - 23 Jan 2004 05:10 GMT
Hi,

That is 100% correct. However, if I am not mistaken there is no way to
create shares using WMI, that is why I believe the WNet* functions are
required for this purpose.

Signature

Chris Taylor
http://dotnetjunkies.com/WebLog/chris.taylor/

> > To work with shares you can use the WNetXXX functions provided in
> > mpr.dll. Here is an example using WNetGetConnection to determine what
[quoted text clipped - 6 lines]
>
> -mdb
Jeremy Chapman - 23 Jan 2004 15:56 GMT
I got WMI to create a share. Thanks for the info guys.

> Hi,
>
[quoted text clipped - 12 lines]
> >
> > -mdb

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.