How to access shared folder in windows 2000/2003 using delphi asp.net?
I have try using TNetResource but not success.
Here's my script that translated from source:
http://support.microsoft.com/kb/842789

I have been add "windows" unit into uses clause but an error occured
like this:
"E2003 Undeclared identifier: 'FillChar'"
I use BDS 2006 on Delphi for Microsoft.Net IDE. But in Delphi for
Microsoft Win32 IDE, everything is ok. What's the problem in .net?

What unit is which i need to use?
How 'FillChar' can be used in .net?

var
  NetResource: TNetResource;
  UserName, Password: string;
  LocalDrive, RemoteUNCPath: String;
  RetValue: DWORD;

  w: TextFile;
begin
  UserName := 'MyAccount';
  Password := 'MyPassword';
  RemoteUNCPath := '\\MyServer\MyShare';
  LocalDrive := 'Z:';

  FillChar(NetResource, SizeOf(NetResource), 0); // clear structure
  NetResource.dwType := RESOURCETYPE_DISK;
  NetResource.lpRemoteName := PChar(RemoteUNCPath);
  NetResource.lpLocalName := PChar(LocalDrive);

  RetValue := WNetAddConnection2(NetResource, PChar(Password),
PChar(UserName), CONNECT_UPDATE_PROFILE);
  if RetValue = NO_ERROR then
  begin
    AssignFile(w, 'X:\MyTextFile.txt');
    if not FileExists('X:\MyTextFile.txt') then
      Rewrite(w) // create new empty file
    else
      Append(w); // append to existing file
    try
      WriteLn(w);
      WriteLn('Hi how are you');
      // Response.Write('Success');
    except
      // Response.Write('Failed');
    end;
    CloseFile(w);
  end
  else
  begin
    // Response.Write('Failed');
  end;
  WNetCancelConnection2(NetResource.lpLocalName, 0, False);
end;

Reply via email to