Arif widiyanto

mind, passions, spirit and hopes

Tulisan terkirim dikaitan (tagged) ‘System Information’

Delphi Mendapatkan info penggunaan memory dari suatu proses

Posted by arifw pada Kamis, 24 April 2008

uses

psAPI;

function GetProcessMemorySize(_sProcessName: string; var _nMemSize: Cardinal): Boolean;

var

l_nWndHandle, l_nProcID, l_nTmpHandle: HWND;

l_pPMC: PPROCESS_MEMORY_COUNTERS;

l_pPMCSize: Cardinal;

begin

l_nWndHandle := FindWindow(nil, PChar(_sProcessName));

if l_nWndHandle = 0 then

begin

Result := False;

Exit;

end;

l_pPMCSize := SizeOf(PROCESS_MEMORY_COUNTERS);

GetMem(l_pPMC, l_pPMCSize);

l_pPMC^.cb := l_pPMCSize;

GetWindowThreadProcessId(l_nWndHandle, @l_nProcID);

l_nTmpHandle := OpenProcess(PROCESS_ALL_ACCESS, False, l_nProcID);

if (GetProcessMemoryInfo(l_nTmpHandle, l_pPMC, l_pPMCSize)) then

_nMemSize := l_pPMC^.WorkingSetSize

else

_nMemSize := 0;

FreeMem(l_pPMC);

Result := True;

end;

procedure TForm1.Button1Click(Sender: TObject);

var

l_nSize: Cardinal;

begin

if (GetProcessMemorySize(‘Unbenannt – Editor’, l_nSize)) then

ShowMessage(‘Size: ‘ + IntToStr(l_nSize) + ‘ byte’)

else

ShowMessage(‘Error’);

end;

Ditulis dalam Delphi, Programming, System Information | Bertanda: | Komentar Dimatikan

Delphi – Get a list of installed services

Posted by arifw pada Kamis, 24 April 2008


const
SERVICE_KERNEL_DRIVER = $00000001;
SERVICE_FILE_SYSTEM_DRIVER = $00000002;
SERVICE_ADAPTER = $00000004;
SERVICE_RECOGNIZER_DRIVER = $00000008;

SERVICE_DRIVER =
(SERVICE_KERNEL_DRIVER or
SERVICE_FILE_SYSTEM_DRIVER or
SERVICE_RECOGNIZER_DRIVER);

SERVICE_WIN32_OWN_PROCESS = $00000010;
SERVICE_WIN32_SHARE_PROCESS = $00000020;
SERVICE_WIN32 =
(SERVICE_WIN32_OWN_PROCESS or
SERVICE_WIN32_SHARE_PROCESS);

SERVICE_INTERACTIVE_PROCESS = $00000100;

SERVICE_TYPE_ALL =
(SERVICE_WIN32 or
SERVICE_ADAPTER or
SERVICE_DRIVER or
SERVICE_INTERACTIVE_PROCESS);

uses WinSvc;

function ServiceGetList(
sMachine : string;
dwServiceType,
dwServiceState : DWord;
slServicesList : TStrings )
: boolean;
const
cnMaxServices = 4096;

type
TSvcA = array[0..cnMaxServices]
of TEnumServiceStatus;
PSvcA = ^TSvcA;

var
j : integer;

schm : SC_Handle;

nBytesNeeded,

nServices,
nResumeHandle : DWord;

ssa : PSvcA;
begin
Result := false;

schm := OpenSCManager(
PChar(sMachine),
Nil,
SC_MANAGER_ALL_ACCESS);

if(schm > 0)then
begin
nResumeHandle := 0;

New(ssa);

EnumServicesStatus(
schm,
dwServiceType,
dwServiceState,
ssa^[0],
SizeOf(ssa^),
nBytesNeeded,
nServices,
nResumeHandle );

for j := 0 to nServices-1 do
begin
slServicesList.
Add( StrPas(
ssa^[j].lpDisplayName ) );
end;

Result := true;

Dispose(ssa);

// close service control
// manager handle
CloseServiceHandle(schm);
end;
end;

ServiceGetList( ”,
SERVICE_WIN32,
SERVICE_STATE_ALL,
ListBox1.Items )

Author: Alexander Savchev

Ditulis dalam Delphi, Programming, System Information | Bertanda: , | Komentar Dimatikan

 
Ikuti

Get every new post delivered to your Inbox.