Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1230
  • Last Modified:

Networking and delphi

i'm just curious If my computer had access to other computers on a network, where would the info be in the registry and can i write a program in delphi that will copy files to those computers?
0
herd_bone
Asked:
herd_bone
  • 5
1 Solution
 
shaneholmesCommented:

  but you can read the network status from the NETINFOSTRUCT.

var lpProvider : Pchar;
    lpNetInfoStruct : _NETINFOSTRUCT;
begin
  WNetGetNetworkInformation(lpProvider,lpNetInfoStruct);
  if lpNetInfoStruct.dwStatus = ERROR_NO_NETWORK then
    // sorry, no network

However, even something simpler is a path  - if you know a path on the network, you can test for files.
If that path exists, there is a network.

Example (utilizing UNC paths)

if fileExists('\\Gaming-station1\shareddocs\Test.txt') then
 ShowMessage('Network exists!');

where, Gaming-station1 is a name of a computer on the network

Also,

Yes, you can write a program to copy files to another computer. This is done all the time, especially in a backup style application.

See this link for an example of copying files (lots of good options) in a Backup application

http://www.delphi.about.com/library/weekly/aa033004a.htm


You could also use the win32 call to

CopyFile(lpExistingFileName: PAnsiChar; lpNewFileName: PAnsiChar; bFailIfExists: LoongBool);

Again, using the UNC path to the folder on the network

Shane
0
 
esoftbgCommented:
Hi herd_bone,

download from        http://www.geocities.com/esoftbg/
                 file        Q_20937024.exe.zip
I can not taste this   Q_20937024.exe because I have not Network at my home. If it works well and you are interested, I will send the source code.

emil
0
 
herd_boneAuthor Commented:
What does it do, basically i need my program to be network aware.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
esoftbgCommented:
simply:
1.Select a source folder (top-left component);
2.Select a source fсle (top-псааве component);
3.Select a target network folder (bottom-left component);
4.Press Copy button.
If it works, the selected file will be copied into the selected network folder.

0
 
esoftbgCommented:
>2.Select a source fсle (top-псааве component);
to be readed as:
2.Select a source file (top-middle component);
0
 
esoftbgCommented:
This is not a new answer of this question. It is the code of the accepted one above. Let it be here if my site would be destroyed in the future for any reason.

Hi herd_bone, if you share your e-mail address I could sent into it the source code which is below as zip file.

unit Unit_Q_20942205;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes,    Graphics, Controls,
  IdGlobal,Dialogs,  Forms,    ComCtrls, ShellCtrls, Buttons,  StdCtrls;

type
  TForm1 = class(TForm)
    ShellListView: TShellListView;
    ShellTreeView: TShellTreeView;
    spbCopy: TSpeedButton;
    Memo: TMemo;
    stv: TShellTreeView;
    lblSourceFolder: TLabel;
    lblSourcefile: TLabel;
    lblResult: TLabel;
    spbClear: TSpeedButton;
    lblTargetfolder: TLabel;
    procedure spbCopyClick(Sender: TObject);
    procedure spbClearClick(Sender: TObject);
  private        { Private declarations }
  public         { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.spbCopyClick(Sender: TObject);
var
  B:      Boolean;
  S:      string;
  T:      string;
  R:      string;
begin
  R := 'File Copy was NOT Successful';
  B := False;
  try
    try
      S := ShellListView.SelectedFolder.PathName;
      if not ShellListView.SelectedFolder.IsFolder then
      begin
        T := ShellTreeView.SelectedFolder.PathName;
        T := T + '\' + ExtractFileName(S);
        B := CopyFileTo(S, T);
      end;
    except
      on e : Exception do
      begin
        B := False;
        R := e.Message;
      end;
    end;
  finally
    if B then
    begin
      Memo.Lines.Add(S);
      Memo.Lines.Add('was SUCCESSFULY COPIED to ');
      Memo.Lines.Add(T);
      Memo.Lines.Add('--------------------------------------------------------------------------------------------------------------------------------');
    end
    else
    begin
      Memo.Lines.Add(R);
      Memo.Lines.Add('--------------------------------------------------------------------------------------------------------------------------------');
    end
  end;
end;

procedure TForm1.spbClearClick(Sender: TObject);
begin
  Memo.Clear;
end;

end.

//................

object Form1: TForm1
  Left = 216
  Top = 89
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'Networking and Delphi'
  ClientHeight = 606
  ClientWidth = 760
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDefaultPosOnly
  PixelsPerInch = 96
  TextHeight = 13
  object spbCopy: TSpeedButton
    Left = 8
    Top = 288
    Width = 320
    Height = 32
    Caption = '    COPY selected source to selected destination    '
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    Glyph.Data = {
      D6030000424DD603000000000000760000002800000048000000180000000100
      0400000000006003000000000000000000001000000000000000000000000000
      8000008000000080800080000000800080008080000080808000C0C0C0000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00888888888888
      8888888888888888888888888888888888888888888888888888888888888888
      8888888888888888888888888888888888888888888888888888888888888888
      8888888888888888888888888888888888888888888888888888888888888888
      8888888888888888888888880778888888888888888888F77888888888888888
      88888888888888888888888888888880007788888888888888888FFF77888888
      8888888888888888888888888888888888888800C0077888888888888888FF8F
      F7788888888888888888880778888888888888888888800CCC00778888888888
      888FF888FF77888888888888888880007788888888888888888800CCCCC00778
      8888888888FF88888FF7788888888888888800C0077888888888888888800CCC
      CCCC0077888888888FF8888888FF77888888888888800CCC0077888888888888
      8800CCCCCCCCC00778888888FF888888888FF778888888888800CCCCC0077888
      88888888800CCCCCCCCCCC007788888FF88888888888FF7788888888800CCCCC
      CC0077888888888800CCCCCCCCCCCCC0077888FF8888888888888FF778888888
      00CCCCCCCCC0077888888880000000CCCCC0000000778FFFFFFF88888FFFFFFF
      778888800CCCCCCCCCCC007788888888888880CCCCC0788888888888888F8888
      8F78888888888800CCCCCCCCCCCCC00778888888888880CCCCC0788888888888
      888F88888F788888888880000000CCCCC000000077888888888880CCCCC07888
      88888888888F88888F788888888888888880CCCCC078888888888888888880CC
      CCC0788888888888888F88888F788888888888888880CCCCC078888888888888
      888880CCCCC0788888888888888F88888F788888888888888880CCCCC0788888
      88888888888880CCCCC0788888888888888F88888F788888888888888880CCCC
      C078888888888888888880000000888888888888888FFFFFFF88888888888888
      8880CCCCC0788888888888888888888888888888888888888888888888888888
      888888888880CCCCC07888888888888888888888888888888888888888888888
      8888888888888888888000000088888888888888888888888888888888888888
      8888888888888888888888888888888888888888888888888888888888888888
      8888888888888888888888888888888888888888888888888888}
    NumGlyphs = 3
    ParentFont = False
    OnClick = spbCopyClick
  end
  object lblSourceFolder: TLabel
    Left = 12
    Top = 8
    Width = 63
    Height = 13
    Caption = 'Source folder'
  end
  object lblSourcefile: TLabel
    Left = 188
    Top = 8
    Width = 50
    Height = 13
    Caption = 'Source file'
  end
  object lblResult: TLabel
    Left = 332
    Top = 8
    Width = 33
    Height = 13
    Caption = 'Result:'
  end
  object spbClear: TSpeedButton
    Left = 384
    Top = 2
    Width = 128
    Height = 22
    Caption = 'Clear Results'
    OnClick = spbClearClick
  end
  object lblTargetfolder: TLabel
    Left = 12
    Top = 324
    Width = 82
    Height = 13
    Caption = 'Destination folder'
  end
  object ShellListView: TShellListView
    Left = 184
    Top = 24
    Width = 144
    Height = 256
    ObjectTypes = [otFolders, otNonFolders]
    Root = 'rfMyComputer'
    ShellTreeView = stv
    Sorted = True
    ReadOnly = False
    HideSelection = False
    TabOrder = 0
    ViewStyle = vsList
  end
  object ShellTreeView: TShellTreeView
    Left = 8
    Top = 340
    Width = 320
    Height = 256
    ObjectTypes = [otFolders]
    Root = 'rfNetwork'
    UseShellImages = True
    AutoRefresh = False
    Indent = 19
    ParentColor = False
    RightClickSelect = True
    ShowRoot = False
    TabOrder = 1
  end
  object Memo: TMemo
    Left = 328
    Top = 24
    Width = 416
    Height = 572
    ReadOnly = True
    TabOrder = 2
  end
  object stv: TShellTreeView
    Left = 8
    Top = 24
    Width = 176
    Height = 256
    ObjectTypes = [otFolders]
    Root = 'rfMyComputer'
    ShellListView = ShellListView
    UseShellImages = True
    AutoRefresh = False
    Indent = 19
    ParentColor = False
    RightClickSelect = True
    ShowRoot = False
    TabOrder = 3
  end
end
0
 
esoftbgCommented:
In addition there are two possible (not tested trough LAN) ways to copy File and Folder:

procedure TForm1.Button_Lan_CopyFileClick(Sender: TObject);
var
  S:      string;
  T:      string;
  R:      string;
begin
  S := 'F:\Q_20932619.txt';
  R := '\\Emo\C:\Q_20932619.txt';
  case CopyFileTo(S, R) of
    True:  T := 'was SUCCESSFULY COPIED to ';
    False: T := 'was NOT SUCCESSFULY COPIED to ';
  end;
  Memo.Lines.Add(S);
  Memo.Lines.Add(T);
  Memo.Lines.Add(R);
  Memo.Lines.Add('--------------------------------------------------------------------------------------------------------------------------------');
end;

function  Copy_Dir(Dir, Source, Target: string): Boolean;
var
  B:      Boolean;
  T:      TSHFileOpStruct;
begin
  B := False;
  if not DirectoryExists(Target+Dir) then
    ForceDirectories(Target);
  try
    Fillchar(T, SizeOf(T), #0);
    with T do
    begin
      Wnd := 0;
      wFunc := FO_COPY;
      pFrom := PChar(Source+Dir + #0#0);
      pTo := PChar(Target+Dir + #0#0);
      fFlags := FOF_ALLOWUNDO or FOF_SILENT or FOF_NOCONFIRMATION;
    end;
    Application.ProcessMessages;
    B := (SHFileOperation(T)=0);
  finally
    Result := B;
  end;
end;

procedure TForm1.Button_Lan_CopyFolderClick(Sender: TObject);
var
  S:      string;
  T:      string;
  R:      string;
  Dir:    string;
begin
  S := 'F:';
  R := '\\emo\C:';
  Dir := '\SFX';
  case Copy_Dir(Dir, S, R) of
    True:  T := 'was SUCCESSFULY COPIED to ';
    False: T := 'was NOT SUCCESSFULY COPIED to ';
  end;
  Memo.Lines.Add(S+Dir);
  Memo.Lines.Add(T);
  Memo.Lines.Add(R+Dir);
  Memo.Lines.Add('--------------------------------------------------------------------------------------------------------------------------------');
end;
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now