![]() |
Inhalt eines Edit an die CMD übergeben?
Hallo,
Ich lese meinen Benutzernamen (Windowskonto) wie folgt in einem Editfeld ein:
Delphi-Quellcode:
Das ist alles noch keine Hürde. Nun kommt mein Problem. Wenn ich jetzt die CMD aufrufe und den Wert aus Edit3 übernehme:
procedure TForm1.FormCreate(Sender: TObject);
begin regist := TRegistry.Create; regist.RootKey := HKEY_LOCAL_MACHINE; regist.OpenKey('\Software\Microsoft\Windows NT\CurrentVersion\Winlogon',True); Edit3.Text:=regist.ReadString('DefaultUserName'); end;
Delphi-Quellcode:
geht nichts mehr!
procedure TForm1.Button8Click(Sender: TObject);
begin ShellExecute(Handle,'open','cmd','/c '+'cacls "c:\System Volume Information" /E /G '+Edit3.Text+':F',nil,SW_NORMAL); end; Wo liegt der Fehler? Kann man so überhaupt einen Wert aus einem Editfeld übernehmen??? Danke! |
Re: Inhalt eines Edit an die CMD übergeben?
ShellExecute erwartet Variablen vom Typ PChar, du kannst den Text vom Editfeld mittels Pchar(Edit.Text) formatieren
|
Re: Inhalt eines Edit an die CMD übergeben?
Folgende Prozedur gibt leider eine Fehlermeldung beim compilieren:
Delphi-Quellcode:
Inkompatible Typen: 'String' und 'PAnsiChar'
procedure TForm1.Button8Click(Sender: TObject);
begin ShellExecute(Handle,'open','cmd','/c '+'cacls "c:\System Volume Information" /E /G '+PChar(Edit3.Text)+':F',nil,SW_NORMAL); end; |
Re: Inhalt eines Edit an die CMD übergeben?
Zitat:
versuch es mal so:
Delphi-Quellcode:
mfG
ShellExecute(Handle, 'open', 'cmd',PChar('/c ' + 'cacls "c:\System Volume Information" /E /G ' + Edit3.Text + ':F'), nil, SW_SHOWNORMAL);
mirage228 |
Re: Inhalt eines Edit an die CMD übergeben?
Jepp, das war's. Danke!!!
|
Re: Inhalt eines Edit an die CMD übergeben?
Moin Mario,
Du hast beim Auslesen einiges vergessen:
|
Re: Inhalt eines Edit an die CMD übergeben?
Moin?! Christian, :wink:
hast recht!!! Du meinst bestimmt alles in einen Try Finally-Block setzen und anschließend regist.free. Key-Prüfung: if regist.KeyExist('Schlüssel') then habe ich nachträglich "eingebaut". (Danke für den Hinweis!!!) Dein zweites Bedenken kann ich allerdings nicht nachvollziehen. Einen schönen 2. Advent!!! :) |
Re: Inhalt eines Edit an die CMD übergeben?
HI!
In der OH steht Writes the current key to the registry and closes the key. Delphi syntax: procedure CloseKey; C++ syntax: void __fastcall CloseKey(void); Description Call CloseKey to write the current key to the registry and close the key. An application should not keep keys open any longer than necessary. Many TRegistry methods routinely call CloseKey after reading from or writing to the registry. Calling CloseKey when there is no current key has no effect. Note: When an application closes a key, the key is written to the registry. The LazyWrite property determines how the write takes place. Ciao Frederic |
Re: Inhalt eines Edit an die CMD übergeben?
Ja danke! Und nun noch mal zu Deutsch?! Ist ja nicht böse gemeint!!!!
|
Re: Inhalt eines Edit an die CMD übergeben?
Hi,
bei mir (Delphi 7) wird im Destruktor von TRegistry die Funktion CloseKey() bereits aufgerufen. Also ist ein zweiter Aufruf nicht mehr nötig. ;) mfG mirage228 |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:49 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz