Is it possible to map a root drive...
Articles and Tips: qna
01 Jan 2003
Q.
Is it possible to map a root drive from a Delphi program?
A.
You can use the Add method of the Session control (NWSess.ocx, NWSess.NWDriveMappings). Alternatively, you can call NWSetDriveBase()--see also the simplified helper function from D_NW.pas:
function U_MapAvailableDrive(path: String; Var drv: nuint16; Var connHandle : NWCONN_HANDLE; Var dirHandle : NWDIR_HANDLE): NWCCODE; { Purpose Map an available drive to the given path Parameters in : path Target path out : drv allocated drive number out : connHandle new connHandle to target server out : dirHandle new dirHandle to target path Returns NW error code See also U_FindAvailableDriveLetter } VAR NewPath : Array[0..255] of Char; begin // get next unmapped drive (starting with Z:) result := U_FindAvailableDriveLetter(drv); if (result=0) then begin Fillchar(newPath, Sizeof(newPath), 0); // split into vol/path result := NWParseNetWarePath (U_pStr(path), connHandle, dirHandle, @NewPath ); if (result=0) then result := NWSetDriveBase(drv, connHandle, dirHandle, @NewPath, 0); end; end;
This sample will map a root drive to your current application directory:
uses CalWin32, D_NW;
procedure TForm1.FormCreate(Sender: TObject); VAR L : record drv : nuint16; connHandle : NWCONN_HANDLE; dirHandle : NWDIR_HANDLE; cCode : NWCCODE; end; begin NWCallsInit(nil, nil); L.cCode := U_MapAvailableDrive(ExtractFile Path(Application.ExeName), L.drv, L.connHandle, L.dirHandle); ShowMessage(Format ('U_MapAvailableDrive returned %04X', [L.cCode])); end;
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.