Autor Beitrag
winx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 249



BeitragVerfasst: Di 25.10.05 12:11 
Hallo,

wie finde ich mit Delphi 7 den NAmen des aktuellen Windows XP Benutzers raus???
Hat da jemand ein Beispiel?

Danke
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Di 25.10.05 12:13 
Schau dir mal die Hilfe zu GetUserName ( WinAPI ) an.

_________________
Bravery calls my name in the sound of the wind in the night...
winx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 249



BeitragVerfasst: Di 25.10.05 12:21 
da bin ich gerade drüber... und versuche es so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
...
function GetName():string;
var pointer : Pchar;
    name : string;
    size : dword;
begin

  GetUserName(pointer,size);
  name := pointer;
  result := name;

end;


aber ich bekomme immer einen leeren String zurück...

wo liegt mein Fehler, habe übrigens WinXP SP2
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Di 25.10.05 12:23 
Naja, solltest für den PCHar noch Speicher reservieren und size auf einen Wert verschieden von 0 ( bei Benutzernamen sollte 32 reichen ) setzen.

_________________
Bravery calls my name in the sound of the wind in the night...
winx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 249



BeitragVerfasst: Di 25.10.05 12:31 
danke hat geklappt :-)
Muetze1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 346



BeitragVerfasst: Di 25.10.05 12:44 
Oder der direkten Arbeit mit echten PChar's aus dem Weg gehen:

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:
  // Returns the username of the actual logged in user.
  //
  // Returns
  //   The username as AnsiString.
  // Remarks
  //   The function won't return the name and family name like "Mike Folk", only
  //   the windows username.
Function Get_Current_Username : AnsiString;
Var
  ldwSize : DWord;
  lName   : String;
Begin
  ldwSize := 60;
  SetLength(lName, ldwSize + 1);

  If GetUserName(@lName[1], ldwSize) Then
    SetLength(lName, ldwSize)
  Else
    lName := 'Unbekannt';

  Result := lName;
End;

_________________
49 63 68 68 61 62 65 6B 65 69 6E 65 41 68 6E 75 6E 67 21