unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellApi, Spin, ExtCtrls;
type
TEasyCMD =
class(TForm)
Bsend: TButton;
Bname: TButton;
Text: TMemo;
Eanzahl: TSpinEdit;
Brefresh: TButton;
ListBox1: TListBox;
procedure BsendClick(Sender: TObject);
procedure BnameClick(Sender: TObject);
procedure EanzahlChange(Sender: TObject);
procedure BrefreshClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
EasyCMD: TEasyCMD;
implementation
type
PNetResourceArray = ^TNetResourceArray;
TNetResourceArray =
array[0..100]
of TNetResource;
function CreateNetResourceList(ResourceType: DWord;
NetResource: PNetResource;
out Entries: DWord;
out List: PNetResourceArray): Boolean;
var
EnumHandle: THandle;
BufSize: DWord;
Res: DWord;
begin
Result := False;
List :=
Nil;
Entries := 0;
if WNetOpenEnum(RESOURCE_GLOBALNET,
ResourceType,
0,
NetResource,
EnumHandle) = NO_ERROR
then begin
try
BufSize := $4000;
// 16 kByte
GetMem(List, BufSize);
try
repeat
Entries := DWord(-1);
FillChar(List^, BufSize, 0);
Res := WNetEnumResource(EnumHandle, Entries, List, BufSize);
if Res = ERROR_MORE_DATA
then begin
ReAllocMem(List, BufSize);
end;
until Res <> ERROR_MORE_DATA;
Result := Res = NO_ERROR;
if not Result
then begin
FreeMem(List);
List :=
Nil;
Entries := 0;
end;
except
FreeMem(List);
raise;
end;
finally
WNetCloseEnum(EnumHandle);
end;
end;
end;
procedure ScanNetworkResources(ResourceType, DisplayType: DWord; List: TStrings);
procedure ScanLevel(NetResource: PNetResource);
var
Entries: DWord;
NetResourceList: PNetResourceArray;
i: Integer;
begin
if CreateNetResourceList(ResourceType, NetResource, Entries, NetResourceList)
then try
for i := 0
to Integer(Entries) - 1
do begin
if (DisplayType = RESOURCEDISPLAYTYPE_GENERIC)
or
(NetResourceList[i].dwDisplayType = DisplayType)
then begin
List.AddObject(NetResourceList[i].lpRemoteName,
Pointer(NetResourceList[i].dwDisplayType));
end;
if (NetResourceList[i].dwUsage
and RESOURCEUSAGE_CONTAINER) <> 0
then
ScanLevel(@NetResourceList[i]);
end;
finally
FreeMem(NetResourceList);
end;
end;
begin
ScanLevel(
Nil);
end;
{$R *.dfm}
procedure TEasyCMD.BsendClick(Sender: TObject);
var send:
String;
i: Integer;
begin
for i := 1
to StrToInt(Eanzahl.text)
do
begin
send := '
send ' + ListBox1.Items.Text + '
' + text.text + '
';
ShellExecute(GetDesktopWindow, '
open', '
net.exe', PChar(send),
nil, SW_HIDE);
end;
end;
function GetComputerName:
String;
var Buffer:
Array[0..MAX_COMPUTERNAME_LENGTH + 1]
of Char;
size: DWord;
begin
size := 1024;
Windows.GetComputerName(Buffer, Size);
Result := StrPas(Buffer);
end;
procedure TEasyCMD.BnameClick(Sender: TObject);
begin
ShowMessage(GetComputerName)
end;
procedure TEasyCMD.EanzahlChange(Sender: TObject);
begin
try
if StrToInt(Eanzahl.Text) < 1
then
begin
Eanzahl.Text := '
1';
end;
except
begin
ShowMessage('
Sie müssen eine Zahl eingeben!!!');
Eanzahl.Text := '
1';
end;
end;
end;
procedure TEasyCMD.BrefreshClick(Sender: TObject);
begin
ScanNetworkResources(RESOURCETYPE_DISK, RESOURCEDISPLAYTYPE_SERVER, ListBox1.Items);
end;