Solved

HDD mapping in a LAN at runtime.

Posted on 1998-11-29
6
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JAudiorecorder record freezing the app 29 92
Firemonkey BASS_Init into a thread 17 83
Firemonkey how to swip panel with finger tap 1 41
TAction.OnAfterExecute? 2 31
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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