Autant passer par l'API Windows http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/windows_networking_reference.asp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 Abstract:How do I map a network drive in Windows NT or '95? Technical Information Database TI1592D.txt How do I map a network drive in Windows NT or '95? Category :Application Interop Platform :All Product :Delphi All Description: How do I map a network drive in Windows NT or '95? You can use the WNetAddConnection2 API call. The prototype for the API call is in Windows.Pas. function WNetAddConnection2W(var lpNetResource: TNetResourceW; lpPassword, lpUserName: PWideChar; dwFlags: DWORD): DWORD; stdcall; To make the call you will need to fill a lpNetResource structure with a minimum set of parameters, shown in the example below. You pass this structure as the first parameter to the call, the password, user name, and a flag that indicates whether this mapping should be persistant every time the machine is logged onto. For more info on the API itself, see Window's Programmers Reference help (find the function in Windows.pas, place your text cursor over the function call, and hit F1 to bring up help). procedure TForm1.Button1Click(Sender: TObject); var NRW: TNetResource; begin with NRW do begin dwType := RESOURCETYPE_ANY; lpLocalName := 'X:'; // map to this driver letter lpRemoteName := 'MyServerMyDirectory'; // Must be filled in. If an empty string is used, // it will use the lpRemoteName. lpProvider := ''; end; WNetAddConnection2(NRW, 'MyPassword', 'MyUserName', CONNECT_UPDATE_PROFILE); end;
Partager