Autor Beitrag
dennor
Hält's aus hier
Beiträge: 2

Win XP
D7 Pro
BeitragVerfasst: Di 24.08.04 12:43 
Ich versuche die Priorität eines laufenden Prozesses zu verändern.

unter Win9x hatte es damals auch so funktioniert, aber unter XP gehts nicht mehr :(

kann mir einer einen rat geben?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, TLHelp32;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    btnrefesh: TButton;
    procedure btnrefeshClick(Sender: TObject);
    procedure ListView1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  aSnapshotHandle: THandle;
  aProcessEntry32: TProcessEntry32;

implementation

{$R *.dfm}

procedure TForm1.btnrefeshClick(Sender: TObject);
var
  bContinue: BOOL;
  NewItem: TListItem;
begin
  ListView1.Items.Clear;
  aSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  aProcessEntry32.dwSize := SizeOf(aProcessEntry32);
  bContinue := Process32First(aSnapshotHandle, aProcessEntry32);
  while Integer(bContinue) <> 0 do
  begin
    NewItem := ListView1.Items.Add;
    NewItem.Caption := ExtractFileName(aProcessEntry32.szExeFile);
    NewItem.subItems.Add(IntToHex(aProcessEntry32.th32ProcessID, 4));
    NewItem.subItems.Add(aProcessEntry32.szExeFile);
    bContinue := Process32Next(aSnapshotHandle, aProcessEntry32);
  end;
  CloseHandle(aSnapshotHandle);
end;


procedure TForm1.ListView1DblClick(Sender: TObject);
var
  Ret: BOOL;
  PrID: Integer; // processidentifier
  Ph: THandle;   // processhandle
begin
  with ListView1 do
  begin
    if MessageDlg('Set Process to High Priority?',
        mtConfirmation, [mbYes, mbNo], 0) = mrYes then
     begin
       PrID := StrToInt('$' + ItemFocused.SubItems[0]);
       Ph := OpenProcess(1, BOOL(0), PrID);
       SetPriorityClass(Ph,HIGH_PRIORITY_CLASS);
     end;
   end;
end;

end.
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Di 24.08.04 13:19 
Ich glaube, dass du dafür die entsprechenden SecurityPrivilegien brauchst. Suche im MSDN SETPRIORITYCLASS

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 24.08.04 14:00 
Welcher Zugriffsart entspricht die "1" im OpenProcess? Verwende da mal PROCESS_SET_INFORMATION.

Gruß,
Jörg
dennor Threadstarter
Hält's aus hier
Beiträge: 2

Win XP
D7 Pro
BeitragVerfasst: Di 24.08.04 17:12 
.Chef hat folgendes geschrieben:
Welcher Zugriffsart entspricht die "1" im OpenProcess? Verwende da mal PROCESS_SET_INFORMATION.

Gruß,
Jörg


super! danke damit klappts
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 26.08.04 20:17 
Und du solltest das Process-Handle auch wieder mit CloseHandle schließen..!

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!