Autor Beitrag
ByStones
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92
Erhaltene Danke: 1

Windows XP
Delphi 2005
BeitragVerfasst: So 28.08.05 19:34 
Hi,

ich hab ein Problem, ich muss ein Variable mit dem Namen User den Namen des angemeldeten Users an dem PC wo das programm läuft Hineinschreiben. Und das gleiche mit System ( es wird die version gemeint z.B.: Xp, 2000, 98, 95, ...)

kann mir da bitte jemand helfen ????


Moderiert von user profile iconChristian S.: Topic aus Sonstiges verschoben am Di 30.08.2005 um 09:49
TM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 74

Win xp
D7 ET
BeitragVerfasst: So 28.08.05 19:39 
Hallo,

von www.dsdt.info/ :

Benutzer:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function GetUsername: String;
var
  Buffer: array[0..255of Char;
  Size: DWord;
begin
  Size := SizeOf(Buffer);
  if not Windows.GetUserName(Buffer, Size) then
    RaiseLastOSError; //RaiseLastWin32Error; {Bis D5};
  SetString(Result, Buffer, Size - 1);
end;


Betriebssystem:
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:
26:
27:
28:
29:
function GetWinVersion: string;
begin
  result:='Unbekannte Version';
  case Win32Platform of
    1:// 9x-Reihe
      If Win32MajorVersion=4 Then Begin
        Case Win32MajorVersion of
            0: result:='Windows 95';
            10: result:='Windows 98';
            90: result:='Windows Me';
        end;
      end;
  2// NT-Reihe
     Case Win32MajorVersion of
         3:IF Win32MinorVersion=51 then
              result:='Windows NT 3.51';
         4:If Win32MinorVersion=0 then
             result:='Windows NT 4';
         5:Case Win32MinorVersion of
              0: result:='Windows 2000';
              1: result:='Windows XP';
              2: result:='Windows .NET Server';
           end;
     End;
  end;
  //Win32CSDVersion enthält Informationen zu Servicepacks
  if Win32CSDVersion<>'' then
    result:=result+' '+Win32CSDVersion;
end;


..

_________________
Dieser Beitrag enthält keine Schreibfehler.
Das sind versteckte Hinweise.
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 28.08.05 19:40 
im eh steht das dazu:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function GetUsername: String;
var
  Buffer: array[0..255of Char;
  Size: DWord;
begin
  Size := SizeOf(Buffer);
  if not Windows.GetUserName(Buffer, Size) then
    RaiseLastOSError; //RaiseLastWin32Error; {Bis D5};
  SetString(Result, Buffer, Size - 1);
end;


RaiseLastOSError ist erst ab Delphi 6 verfügbar. Programmierer, die mit älteren Versionen arbeiten müssen an dieser Stelle RaiseLastWin32Error verwenden.

Zusätzlich sei noch erwähnt, dass die BDE eine gleichlautende Funktion mitbringt, die allerdngs nur vernünftig arbeitet, wenn eine Verbindung zu einer Datenbank besteht.

uind noch das für das os(win)
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:
26:
27:
28:
29:
function GetWinVersion: string;
begin
  result:='Unbekannte Version';
  case Win32Platform of
    1:// 9x-Reihe
      If Win32MajorVersion=4 Then Begin
        Case Win32MajorVersion of
            0: result:='Windows 95';
            10: result:='Windows 98';
            90: result:='Windows Me';
        end;
      end;
  2// NT-Reihe
     Case Win32MajorVersion of
         3:IF Win32MinorVersion=51 then
              result:='Windows NT 3.51';
         4:If Win32MinorVersion=0 then
             result:='Windows NT 4';
         5:Case Win32MinorVersion of
              0: result:='Windows 2000';
              1: result:='Windows XP';
              2: result:='Windows .NET Server';
           end;
     End;
  end;
  //Win32CSDVersion enthält Informationen zu Servicepacks
  if Win32CSDVersion<>'' then
    result:=result+' '+Win32CSDVersion;
end;


Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.
TM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 74

Win xp
D7 ET
BeitragVerfasst: So 28.08.05 19:42 
Haha, war schneller :wink:

..

_________________
Dieser Beitrag enthält keine Schreibfehler.
Das sind versteckte Hinweise.
Holgerwa
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 325

WIN XP Pro, Vista Business
Delphi 7 Pro, BDS 2006 Pro
BeitragVerfasst: So 28.08.05 19:46 
Hallo,

ich nehme mal an, daß bei der Funktion GetWinVersion in der Zeile 7
ausblenden Delphi-Quelltext
1:
Case Win32MinorVersion of					

stehen soll... bei beiden Postings.

@TM: Oder ist das einer dieser versteckten Hinweise? :)

Holger
TM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 74

Win xp
D7 ET
BeitragVerfasst: So 28.08.05 19:54 
Keine Ahnung, ich habs nur rauskopiert.
Ich konnts nor bei mir ausprobieren und xp erkennts richtig.
Aber könnte sein, weil auf meinem Notebook mit Me zeigts "unbekannt" an.

Um genaueres zu sagen fehlts mir leider an Verständnis, was dieser Text bewirkt :(

..

_________________
Dieser Beitrag enthält keine Schreibfehler.
Das sind versteckte Hinweise.
Holgerwa
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 325

WIN XP Pro, Vista Business
Delphi 7 Pro, BDS 2006 Pro
BeitragVerfasst: So 28.08.05 20:04 
Hallo,

@TM: Wenn Du das hier schreibst:
ausblenden Delphi-Quelltext
1:
If Win32MajorVersion=4 Then Begin					

dann ist diese Bedingung ja nur erfüllt, wenn Win32MajorVersion = 4 ist, also wäre ein anschießender Vergleich, ob der Wert 0, 10 oder 90 ist, sinnlos. Und es geht ja dann auch um die "Unterversion", also die Minorversion.

Holger
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 28.08.05 20:11 
Ich bin hier mit: www.luckie-online.de.../WindowsVersion.html eigentlich immer sehr gut gefahren.

Und für den Bneutzer:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function GetCurrUserName: string;
var
  Size                   : DWORD;
begin
  Size := MAX_COMPUTERNAME_LENGTH + 1;
  SetLength(Result, Size);
  if GetUserName(PChar(Result), Size) then
    SetLength(Result, Size)
  else
    Result := '';
end;
TM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 74

Win xp
D7 ET
BeitragVerfasst: Mo 29.08.05 13:33 
@Holgerwa: Ok, klingt logisch.

Und da es so auch nicht funktioniert (wie gesagt, mein Me ist "unbekannt") glaub ich dir einfach mal.

..

_________________
Dieser Beitrag enthält keine Schreibfehler.
Das sind versteckte Hinweise.
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Di 30.08.05 09:32 
hallo!

ich denke, dass es hier im Forum genug antworten (incl. sourcecode) gibt - da muss man nicht unbedingt auf fremde resourcen verlinken.

@ByStones: such einfach hier im Forum nach Suche in: Delphi-Forum, Delphi-Library GETUSERNAME und nach Suche in: Delphi-Forum, Delphi-Library GETVERSIONEX. solltest ein paar treffer erzielen. ;-)

lg martin
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 30.08.05 13:49 
user profile iconMartin1966 hat folgendes geschrieben:
ich denke, dass es hier im Forum genug antworten (incl. sourcecode) gibt - da muss man nicht unbedingt auf fremde resourcen verlinken.

Meinst du mich? Auf meiner HP weiß ich, wo es steht, hier im Forum müsste ich erst suchen.