Solved

HDD mapping in a LAN at runtime.

Posted on 1998-11-29
6
250 Views
Last Modified: 2010-08-05
I need to map a hard disk from a PC into mine at runtime, example:
\\Server\c    ==> D: (in my macine)
Hou could I do it?
0
Comment
Question by:forns
  • 3
  • 3
6 Comments
 
LVL 7

Accepted Solution

by:
BlackMan earned 50 total points
ID: 1348560
Here's a snip from one of my units... For more detailed info, you should check the Win32 help for WNetAddConnection2

unit LBSNet;

interface

Uses
  Winsock, Messages,
  Windows, WinSpool, Classes, SysUtils;

Var
  NetRes : PNetResource;


Function TNetConnector.ConnectDisk(LocalName, RemoteName : String) : Integer;
Begin
  With NetRes^ Do
  Begin
    dwType := RESOURCETYPE_DISK;
    lpLocalName := PChar(LocalName);
    lpRemoteName := PChar(RemoteName);
    lpProvider := '';
  End; (* With *)
  Result := WNetAddConnection2(FNetRes^, nil, nil, 0);
End; (* Procedure Connect *)


Begin
  ConnectDisk('D:', '\\server\c');
End.
0
 

Author Comment

by:forns
ID: 1348561
hey, blackman! i tried that code in my lan with some modifications, but i have some problems:
i made a form with 2 textboxes, one for the remote machine "Server\c" and another one for the now local unit "D:". i put 2 buttons: one to connect and another one to disconnect.
the answer to OnClick is "ConnectDisk(txtLocal.Text, txtRemot.Text), so it calls your function. i modified your function declaring the PNetResource variable in it.

the problem:
ok, it works, but when i exit the program it launches an exception:
Exception EAccessViolation in module PROJECT1.EXE at 0000AEFE.
Acces violation at adress 0040AEFE in module 'PROJECT1.EXE'.
Read of adress 5C33312D.

i tried to declare the PNetResource variable as a global variable, but it launches:
Acces violation at adress 0042E505 in module 'PROJECT1.EXE'.
Read of adress FFFFFFFF.

could you plz tell me what's the problem?
thanx
0
 

Author Comment

by:forns
ID: 1348562
hey, blackman! i tried that code in my lan with some modifications, but i have some problems:
i made a form with 2 textboxes, one for the remote machine "Server\c" and another one for the now local unit "D:". i put 2 buttons: one to connect and another one to disconnect.
the answer to OnClick is "ConnectDisk(txtLocal.Text, txtRemot.Text), so it calls your function. i modified your function declaring the PNetResource variable in it.

the problem:
ok, it works, but when i exit the program it launches an exception:
Exception EAccessViolation in module PROJECT1.EXE at 0000AEFE.
Acces violation at adress 0040AEFE in module 'PROJECT1.EXE'.
Read of adress 5C33312D.

i tried to declare the PNetResource variable as a global variable, but it launches:
Acces violation at adress 0042E505 in module 'PROJECT1.EXE'.
Read of adress FFFFFFFF.

could you plz tell me what's the problem?
thanx
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 7

Expert Comment

by:BlackMan
ID: 1348563
Hmm, I can see that, seems like I cut to hard from my unit :-)
I'll be home in about 3 hours, then I'll post the rest for you.. Sorry!
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1348564
I just found the mising link.. Just add a New(NetRes) to your code. Here's my test unit:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

Var
  NetRes : PNetResource;

Function ConnectDisk(LocalName, RemoteName : String) : Integer;
Begin
  With NetRes^ Do
  Begin
    dwType := RESOURCETYPE_DISK;
    lpLocalName := PChar(LocalName);
    lpRemoteName := PChar(RemoteName);
    lpProvider := '';
  End; (* With *)
  Result := WNetAddConnection2(NetRes^, nil, nil, 0);
End; (* Procedure Connect *)


procedure TForm1.Button1Click(Sender: TObject);
begin
  New(NetRes);
  ConnectDisk('y:', '\\netnews\spfile');
end;

end.
0
 

Author Comment

by:forns
ID: 1348565
That's the way, man! Just what I was looking for!

Thanks a lot, BlackMan, it looks like that New() works as malloc() in C, doesn't it? And Dispose() as Free(). Cool.

It's been very usefull. See you!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 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