Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to rename shares/directories

10 views
Skip to first unread message

Jeremy Chapman

unread,
Jan 14, 2004, 7:59:02 PM1/14/04
to
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

unread,
Jan 17, 2004, 8:18:59 AM1/17/04
to
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

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

"Jeremy Chapman" <NoS...@Please.com> wrote in message
news:uPyfFLw2...@TK2MSFTNGP10.phx.gbl...

Michael Bray

unread,
Jan 22, 2004, 6:38:24 PM1/22/04
to
"Chris Taylor" <chris_t...@hotmail.com> wrote in
news:#ehxzxP3...@TK2MSFTNGP11.phx.gbl:
> 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

unread,
Jan 23, 2004, 12:10:45 AM1/23/04
to
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.

"Michael Bray" <mbrayXXnoS...@SkPiAlMl.ctiusa.com> wrote in message
news:Xns9478BD9E4B23Cmb...@207.46.248.16...

Jeremy Chapman

unread,
Jan 23, 2004, 10:56:01 AM1/23/04
to
I got WMI to create a share. Thanks for the info guys.


"Chris Taylor" <chris_t...@hotmail.com> wrote in message
news:OIkX$8W4DH...@TK2MSFTNGP12.phx.gbl...

0 new messages