Solved

Network address instead of drive letter.

Posted on 1998-11-16
12
298 Views
Last Modified: 2010-04-04
Using Microsoft Word it is possible to open and manipulate files on a network server by putting the IP address in the path instead of the drive letter.

Example:

I have a UNIX server with the IP number 193.133.116.1
I can map a file system on this server to drive on my PC,
say /data on the server to drive Fl appear in the windows explorer as /data on '193.133.116.1' (F:).

Obviously this is using TCP/IP as the network protocol.

I can then access this drive through Word as either F: or without mapping the drive as \\193.133.116\/data.

How can I use the second method with my applications in Delphi 3 ?

John Morin
0
Comment
Question by:nhoj
  • 6
  • 2
  • 2
  • +1
12 Comments
 
LVL 2

Expert Comment

by:333
ID: 1347000
Hi,
I'm not sure if it works with IP address, but i tested it with computer network name.
If you want to open a file on the network:
RichEdit1.Lines.LoadFromFile('\\mycomputer\share_c\autoexec.bat');

If you have mapped drive and you want to get full path then:
label1.caption:=ExpandUNCFileName('f:\autoexec.bat');
If drive F is mapped to \\mycomputer\share_c then label1.caption will be
''\\mycomputer\share_c'

A.
0
 
LVL 1

Accepted Solution

by:
jecksom earned 100 total points
ID: 1347001
hi nhoj!

As you said you have "Unix" server and probably Samba daemon installed on it,
you could access resources only via netbios (that can be differs from nds) name like :
\\server\<user_or_resource_name>\<file> , in case this "Unix" server is in your network
segment or whatever annouced you don't have to worry about IP<-> Netbios address
translation, windows do it for you , but if you want to access machine in different (not announced
segment) you have to put <IP     NETBIOS name> in your \windows\lmhosts file and then
connect as "usually". Check WNetAddConnection2 for "usually" connection.

Jecksom

0
 
LVL 1

Expert Comment

by:hustch
ID: 1347002
1) ExpandUNCFileName also copies the filename (ExpandUNCFileName('f:\autoexec.bat') = '\\mycomputer\share_c\autoexec.bat' if drive F is mapped to \\mycomputer\share_c

2) It is possible, to have then same share mappet two different ways, eg. F: as \\mycomputer\share_c and G: as \\ip-number\share_c
Then ExpandUNCFileName('f:\autoexec.bat') = '\\mycomputer\share_c\autoexec.bat'
and ExpandUNCFileName('g:\autoexec.bat') = '\\ip-number\share_c\autoexec.bat'
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 1

Expert Comment

by:jecksom
ID: 1347003
nhoj, just map letter read file and unmap letter:

var
  nr:TNetResource;

procedure TForm1.Button1Click(Sender: TObject);
begin
nr.lpRemoteName:=stralloc(255);
nr.lpLocalName:=stralloc(255);
nr.dwType:=RESOURCETYPE_ANY;
StrPCopy(nr.lplocalName,  'f:'); // let say H:
StrPCopy(nr.lpremoteName, '\\195.18.32.62\jecksom\core');
nr.lpProvider:=nil;
if no_error=
WNetAddConnection2(nr,'password','login',CONNECT_RESERVED) then
begin
memo1.lines.LoadFromFile('f:\core');
if no_error<>WNetCancelConnection2('h:',0,false) then
showmessage('error unmapping');
end else showmessage('error mapping');
strdispose(nr.lpRemoteName);
strdispose(nr.lpLocalName);
end;

Jecksom
0
 
LVL 1

Expert Comment

by:jecksom
ID: 1347004
in my example must be :

WNetCancelConnection2('f:',0,false) // not h:
  and
you have to change  <IP> and <login> <password>.

0
 
LVL 1

Expert Comment

by:jecksom
ID: 1347005
Oh , line
memo1.Lines.LoadFromFile('\\193.133.116.1\resource\file'); , working too.

0
 
LVL 1

Expert Comment

by:hustch
ID: 1347006
You don't have to map the share to read the file, you can just open the file as '\\server\share\filename'.
0
 
LVL 1

Expert Comment

by:jecksom
ID: 1347007
hustch: yes.
0
 
LVL 2

Expert Comment

by:333
ID: 1347008
That's what I say.

A.
0
 
LVL 1

Expert Comment

by:jecksom
ID: 1347009
333: yep, your first comment was answer on question , sorry , will wait when nhoj awake.

0
 
LVL 1

Author Comment

by:nhoj
ID: 1347010
nhoj is awake!
I need some time to try these things.
0
 
LVL 1

Author Comment

by:nhoj
ID: 1347011
\\server_name\directory_name\file OR
\\IP_address\directory_name\file
work equally well.

When connecting to UNIX servers the slashes in the path must all be \ as in Windows and NOT / as is normal in UNIX. This is where I went wrong before.

Thanks
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Process Javascript errors with Delphi TWebBrowser 1 129
select query - oracle 16 100
Delphi: Connect to running MS Outlook 4 78
How to Get Images From Server using App Tethering 11 20
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now