I need to be able to connect / disconnect to a range of different file servers, map drives, check for connections etc. 
Author Message
 I need to be able to connect / disconnect to a range of different file servers, map drives, check for connections etc.

I try  this :

public static extern long WNetAddConnection2(NETRESSOURCE
lpNetRessource,string lpPassword,string lpUserName,long dwFlags);

But I have allways this error code in return : 487

The Framework has no classes exposing the Netxxxx API's, but you could
simply use the System.Diagnostic.Process class to shell-out a
net use command.

Here's a snippet:

string device = "X:";

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = String.Format("/c net use {0} {1}", device, uncpath);
psi.WindowStyle = ProcessWindowStyle.Minimized;
Process proc = Process.Start(psi);



first off many thanks for the numerous posts. There seems to be a bit of
confusion concerning exactly what my problem is, so i'll explain again.

I am looking for the .net versions of the WNet function provided by the
mpr.dll eg:

I have used all of these functions successfully from VB6 using declare
statements to import them from the mpr.dll, but was hoping that I would not
have to resort to declare statements in dot net.

Maybe i'm expecting too much but i kinda thought there would be something
like 'system.net.addconnection' but I haven't been able to find it.

Anyway to cut a long story short i decided to give Microsoft a try, and
today I used one of my MSDN Universal subscription calls at Mcrosoft to see
if they could point me in the right direction. I have just received a
reply - very speedy, very friendly, well done microsoft - unfortunatley they
simply gave me the code need to import the functions from the mpr.dll into

Maybe there are no .net versions of the functions and I will have to use the
good old declare/dllimport statement. I will send a reply to Microsoft
asking for clarification and will post the result.

once again many thanks
lee robinson

Mon, 01 Nov 2004 03:10:39 GMT  
 [ 1 post ] 

 Relevant Pages 

1. I am not able to see my database class members in class view - Please help

2. Hey Friends I am Not Able To View the Messages Posted

3. How to connect to a Jet database, insert a row, and disconnect via MFC

4. How to Connect and disconnect a netwok drive

5. Connecting/Disconnecting to the Net

6. How to Connect and disconnect a netwok drive

7. Detect when network is connected or disconnected

8. C# , i am trying to create a file on the server using C#

9. Disconnected from server (RPC_E_DISCONNECTED) in MTA

10. Problem with IDL for COM server returning ADO disconnected Recordset

11. Disconnecting/logging off user from server (domain)???? URGENT

12. Disconnecting SQL Server


Powered by phpBB® Forum Software