Solved

HDD mapping in a LAN at runtime.

Posted on 1998-11-29
6
247 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

22 Experts available now in Live!

Get 1:1 Help Now