Blog

02/06/2010 23:06

Messages, hooks & registry

26/05/2010 00:05

Learn by example

25/05/2010 14:02

yummy

24/05/2010 20:18

Advanced delphi

24/05/2010 16:05

Delphi console application

24/05/2010 14:22

Network Resources Mapping

  var
    NetResource : TNetResource;
  begin
    NetResource.dwType := RESOURCETYPE_DISK;
    NetResource.lpLocalName := 'm:'; {use here letters A-Z that are not already mapped}
    NetResource.lpRemoteName := '\\computer_name\resource_name';
    NetResource.lpProvider := '';
    WNetAddConnection2(NetResource, '[password]', '[user]', CONNECT_UPDATE_PROFILE);
  end;

 

For disconnecting the resource:

  function DisconnectNetworkDrive(const drive : string; const force, restore, displayError : boolean) : DWORD;
    // force: should disconnection occur if there are open files or jobs on the connection
    // restore: should continue to restore the connection at the next logon
    // displayError: show the failure reason if any
    var
      return, dwFlags : DWORD;
    begin
      if restore then
        dwFlags := CONNECT_UPDATE_PROFILE
      else
        dwFlags := 0;
      return := WNetCancelConnection2(PChar(drive), dwFlags, force);
      if (return <> NO_ERROR) and (displayError) then
      begin
        Application.MessageBox(PChar('Could not disconnect, reason:' + #13#10 + SysErrorMessage(GetLastError)),
          'DisconnectNetworkDrive', MB_OK);
      end;
      result := return;
    end;

 

Or just connect to the resource, no mapping:

 

function ConnectServer(path: string): boolean;
var
  res : TNetResource;
  reslt : Cardinal;
begin
  if (sUser <> '') and (sPass <> '') then
  begin
    res.dwType  := RESOURCETYPE_DISK;
    res.lpLocalName := nil;
    res.lpRemoteName := PChar(path);
    res.lpProvider := nil;

    reslt := WNetAddConnection2(res, PWideChar(sPass),
      PChar(sUser), CONNECT_UPDATE_RECENT or CONNECT_TEMPORARY);

    if reslt <> NO_ERROR then
    begin
      WriteLn('Cannot connect to destination server with supplied credentials' + #13#10 + 'Error code = ' + IntToStr(reslt));
      WriteLn('  Credentials used were: ' + sUser + ' - ' + sPass);
      Result := false;
    end
    else
      Result := true;
  end
  else
    // if empty credentials, consider that connect/disconnect are disabled
    Result := true;
end;

25/04/2010 13:24

Testing vs. Checking

24/04/2010 12:59

Process explorer - Performance info

Process performance info:

 

Global system performance info:

20/04/2010 00:00

Delphi performance testing

Building the documentation...

 

Raw data to be obtained after running the performance routines:

  type
    TPerformance_Information = packed record
      GlobalMemory_MemoryLoad : Double;
      GlobalMemory_TotalPhys : Double;
      GlobalMemory_AvailPhys : Double;
      GlobalMemory_TotalPageFile : Double;
      GlobalMemory_AvailPageFile : Double;
      GlobalMemory_TotalVirtual : Double;
      GlobalMemory_AvailVirtual : Double;
      ProcessMemory_WorkingSetSize : Double;
      ProcessMemory_Size : Double;
      ProcessMemory_Peak : Double;
      ProcessMemory_PageFault : Double;
      GlobalCPUUsage : Double;
      ProcessCPUUsage : Double;
      ActionTime : Double;
    end;

19/04/2010 00:00

First blog

Interesting stuff: Pushing the limits of Windows

Search site

Contact