Mega Code Archive

 
Categories / Delphi / Examples
 

Dialogs to connect or disconnect mapped network drives

There are two functions WNetConnectionDialog and WNetDisconnectionDialog that will display these dialogs. They are defined in unit Windows (Delphi 5). The first parameter Handle identifies the owning window by its window handle. Note: These Win32 API calls only brings up the network connections dialog. If you want to map programmatically a specific (remote or local) directory to a specific drive letter, then I recommend creating a temporary batch file with a command like this: NET USE N: \\192.168.0.3\C$\Temp This only works if the currently logged in user has an identical account on the remote machine. Otherwise the batch file will ask for the password during execution - ugly. To remove a mapping programmatically, create a batch file with a command like this: NET USE N: /DELETE begin // show the connect dialog WNetConnectionDialog(Handle, RESOURCETYPE_DISK); // ... // show the disconnect dialog WNetDisconnectDialog(handle, RESOURCETYPE_DISK); end;