Autor Beitrag
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Sa 01.05.04 19:15 
Habe nun folgende Funktion integriert, um herauszufinden, ob die AutoPlay-Funktion von Windows aktiviert ist:
ausblenden 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:
procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegistry;
  RegKey: DWORD;
  Key: string;
begin 
  Reg := TRegistry.Create;
  try
    Reg.RootKey :=  HKEY_LOCAL_MACHINE;
    Key := 'SYSTEM\CurrentControlSet\Services\CDRom';
    if Reg.OpenKeyReadOnly(Key) then 
    begin
      if Reg.ValueExists('Autorun') then
      begin
        RegKey := Reg.ReadInteger('Autorun');
        Reg.CloseKey;
        if IntToStr(RegKey)='1' then
          ShowMessage('AutoPlay ist noch aktiv!');
        if IntToStr(RegKey)='0' then
          ShowMessage('AutoPlay ist bereits deaktiviert.');
      end;
    end;
  finally
    Reg.Free 
  end;
end;


Nun möchte ich aber nicht eine extra Nachrichtenbox, sondern der Text soll als "Label" erscheinen und außerdem eine Schaltfläche aktivieren (bei RegKey=0 "Autoplay aktivieren", bei RegKey=1 "Autoplay deaktivieren").[/code]


Zuletzt bearbeitet von CrazyLuke am Sa 01.05.04 19:43, insgesamt 2-mal bearbeitet
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Sa 01.05.04 19:22 
Hallo,

irgendwie verstehe ich nicht ganz, was Du meinst...

Evtl so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
  ...
  ... 
  if Reg.ValueExists('Autorun') then 
  begin 
    RegKey := Reg.ReadInteger('Autorun'); 
    Reg.CloseKey; 
  end; // if
  if (RegKey=1) then Label1.Caption:='AutoPlay ist noch aktiv!'
    else Label1.Caption:='AutoPlay ist bereits deaktiviert.';
  Button1.Enabled:=(RegKey=1);
  ...
  ...

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
CrazyLuke Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Sa 01.05.04 19:29 
Danke, es funzt:

ausblenden 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:
procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegistry;
  RegKey: DWORD;
  Key: string;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey :=  HKEY_LOCAL_MACHINE;
    Key := 'SYSTEM\CurrentControlSet\Services\CDRom';
    if Reg.OpenKeyReadOnly(Key) then
    begin
      if Reg.ValueExists('Autorun') then
      begin
        RegKey := Reg.ReadInteger('Autorun');
        Reg.CloseKey;
        if IntToStr(RegKey)='1' then
          Label50.Caption:='AutoPlay ist noch aktiv!';
          Button2.Enabled:=(IntToStr(RegKey)='1');
        if IntToStr(RegKey)='0' then
            Label50.Caption:='AutoPlay ist bereits deaktiviert.';
            Button5.Enabled:=(IntToStr(RegKey)='0')
      end;
    end;
  finally
    Reg.Free
  end;
end;


Mit dem "else" hats nicht gefunzt (der hat ein "end" erwartet). aber so klappts 1a 8) [/code]
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Sa 01.05.04 19:34 
Hallo,

der Code funktioniert so, wie er dasteht!!! Was ich nicht verstehe ist, dass Du eine Zahl in einen String umwandelst um ihn dann zu vergleichen!?? Das ist so nicht notwendig und total überflüssig.

Zum Verständnis:
ausblenden 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:
procedure TForm1.Button1Click(Sender: TObject); 
var 
  Reg: TRegistry; 
  RegKey: DWORD; 
  Key: string; 
begin 
  Reg := TRegistry.Create; 
  try 
    Reg.RootKey :=  HKEY_LOCAL_MACHINE; 
    Key := 'SYSTEM\CurrentControlSet\Services\CDRom'; 
    if Reg.OpenKeyReadOnly(Key) then 
    begin 
      if Reg.ValueExists('Autorun') then 
      begin 
        RegKey := Reg.ReadInteger('Autorun'); 
        Reg.CloseKey; 
      end; 
    end; 
    if (RegKey=1) then Label50.Caption:='AutoPlay ist noch aktiv!' 
      else Label50.Caption:='AutoPlay ist bereits deaktiviert.'; 
    Button2.Enabled:=(RegKey=1); 
  finally 
    Reg.Free 
  end; 
end;

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
CrazyLuke Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Sa 01.05.04 19:41 
Danke. Noch ein "Button5.Enabled:=(RegKey=0);" und es ist komplett :-D

Ne Frage: Wenn man unter 2000/NT/XP nicht als Admin eingeloggt ist, kommt ne Fehlermeldung, oder?
Kann man ne Admin-Abfrage stellen, wenn se benötigt wird? Muss man diese an allen Stellen angeben, an denen sie benötigt werden könnte oder reciht einmal,so dass diese immer dann aufgerufen wird, wenn se benötigt wird?

Ciao.