T
Thorsten Dittmar
Hi,
I'm having troubles creating network drives programmatically. I need to
map drive "O:" (which is not in use on my system) to a network share
from a C# application.
I'm using the following code:
[DllImport("mpr.dll")]
public static extern ERRORS WNetAddConnection3(IntPtr hWndOwner, ref
NetResource pnetResource, string psPassword, string psUsername, int
piFlags);
.... SNIP ...
Define RESOURCESCOPE, RESOURCETYPE, etc. as enums here
.... SNIP
MPRApi.NetResource pnetRes = new MPRApi.NetResource();
pnetRes.dwScope = MPRApi.RESOURCESCOPE.GLOBALNET;
pnetRes.dwType = MPRApi.RESOURCETYPE.DISK;
pnetRes.dwDisplayType = MPRApi.RESOURCEDISPLAYTYPE.SHARE;
pnetRes.dwUsage = MPRApi.RESOURCEUSAGE.CONNECTABLE;
pnetRes.lpRemoteName = share;
pnetRes.lpLocalName = "O:";
pnetRes.lpProvider = null;
MPRApi.ERRORS err = MPRApi.WNetAddConnection3(this.Handle, ref pnetRes,
password, user, 0);
if (err != MPRApi.ERRORS.ERROR_SUCCESS)
throw new Win32Exception((int)err);
When I execute this code, I keep getting ERROR_BAD_DEVICE as result code.
Can anybody tell me what I'm doing wrong?
Thanks
Thorsten
I'm having troubles creating network drives programmatically. I need to
map drive "O:" (which is not in use on my system) to a network share
from a C# application.
I'm using the following code:
[DllImport("mpr.dll")]
public static extern ERRORS WNetAddConnection3(IntPtr hWndOwner, ref
NetResource pnetResource, string psPassword, string psUsername, int
piFlags);
.... SNIP ...
Define RESOURCESCOPE, RESOURCETYPE, etc. as enums here
.... SNIP
MPRApi.NetResource pnetRes = new MPRApi.NetResource();
pnetRes.dwScope = MPRApi.RESOURCESCOPE.GLOBALNET;
pnetRes.dwType = MPRApi.RESOURCETYPE.DISK;
pnetRes.dwDisplayType = MPRApi.RESOURCEDISPLAYTYPE.SHARE;
pnetRes.dwUsage = MPRApi.RESOURCEUSAGE.CONNECTABLE;
pnetRes.lpRemoteName = share;
pnetRes.lpLocalName = "O:";
pnetRes.lpProvider = null;
MPRApi.ERRORS err = MPRApi.WNetAddConnection3(this.Handle, ref pnetRes,
password, user, 0);
if (err != MPRApi.ERRORS.ERROR_SUCCESS)
throw new Win32Exception((int)err);
When I execute this code, I keep getting ERROR_BAD_DEVICE as result code.
Can anybody tell me what I'm doing wrong?
Thanks
Thorsten