How to Map a Network drive

G

Gavaskar

Hello

What's the best way to map a network in .Net? It's pretty easy in a VB
script, so I thought .Net would be just as easy, but I can't find anything.
I know you can start Net.exe in a process and do it that way, but I thought
the system.Net class should allow me to map a drive.

Any ideas?
 
G

Gavaskar

Can I use that with a username and password?

Jeff Gaines said:
Hello

What's the best way to map a network in .Net? It's pretty easy in a VB
script, so I thought .Net would be just as easy, but I can't find
anything. I know you can start Net.exe in a process and do it that way,
but I thought the system.Net class should allow me to map a drive.

Any ideas?

You will need to use the API, I have the following library functions:

public static void MapNetworkDrive(IntPtr ipParent)
{
const int RESOURCETYPE_DISK = 0x1;
int intReturn = WNetConnectionDialog(ipParent, RESOURCETYPE_DISK);
}

public static void DisconnectNetworkDrive(IntPtr ipParent)
{
const int RESOURCETYPE_DISK = 0x1;
int result = WNetDisconnectDialog(ipParent, RESOURCETYPE_DISK);
}


DLL Prototypes:
// WNetConnectionDialog
[DllImport("mpr.dll", EntryPoint = "WNetConnectionDialog", SetLastError =
true, CharSet = CharSet.Auto)]
public static extern int WNetConnectionDialog(IntPtr whnd, int dwType);

// WNetDisconnectDialog
[DllImport("mpr.dll", EntryPoint = "WNetDisconnectDialog", SetLastError =
true, CharSet = CharSet.Auto)]
public static extern int WNetDisconnectDialog(IntPtr whnd, int dwType);
 
G

Gavaskar

Also, does this call bring up a dialong box? Is there anyway to not have
that appear, or another call that will do that sme thing?
Jeff Gaines said:
Hello

What's the best way to map a network in .Net? It's pretty easy in a VB
script, so I thought .Net would be just as easy, but I can't find
anything. I know you can start Net.exe in a process and do it that way,
but I thought the system.Net class should allow me to map a drive.

Any ideas?

You will need to use the API, I have the following library functions:

public static void MapNetworkDrive(IntPtr ipParent)
{
const int RESOURCETYPE_DISK = 0x1;
int intReturn = WNetConnectionDialog(ipParent, RESOURCETYPE_DISK);
}

public static void DisconnectNetworkDrive(IntPtr ipParent)
{
const int RESOURCETYPE_DISK = 0x1;
int result = WNetDisconnectDialog(ipParent, RESOURCETYPE_DISK);
}


DLL Prototypes:
// WNetConnectionDialog
[DllImport("mpr.dll", EntryPoint = "WNetConnectionDialog", SetLastError =
true, CharSet = CharSet.Auto)]
public static extern int WNetConnectionDialog(IntPtr whnd, int dwType);

// WNetDisconnectDialog
[DllImport("mpr.dll", EntryPoint = "WNetDisconnectDialog", SetLastError =
true, CharSet = CharSet.Auto)]
public static extern int WNetDisconnectDialog(IntPtr whnd, int dwType);
 
J

Jeff Gaines

Also, does this call bring up a dialong box? Is there anyway to not have
that appear, or another call that will do that sme thing?

If you don't want a dialog then you could run with Mr Arnold's suggestion
of 'NET USE'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top