Delphi IDE (89)
Windows with Delphi (280)
New related comments
Number of comments in the last 48 hours
Make TWebBrowser post a form
Sending an email from Delphi using MAPI
Progress bar with the TWebBrowser component
Changing the TCP/IP DNS address
Map or unmap a network disk at run-time
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:I want to attach to a file server and map a network disk from within my Delphi application. How can I do this?
Answer:You need to use the Windows API function WNetAddConnection2 to map a remote share as a disk.
This function replaces the old WNetAddConnection call which did not allow to specify a username.
If you need to specify a user name or password you can do this in arguments 2 (password) and 3 (user name). Note that example below sends nil. If you send nil as user name and password, then WNetAddConnection2 will use the user context for the running process and the password associated with this account.
Note that supplying a user name/ password other than the process currently running will only work on Windows NT, Windows 2000 and Windows XP.
Finally use WNetCancelConnection2() to remove a network mapping.