Entwickler-Ecke
Windows API - Windowspfad rausbekommen?
majolo - Di 24.09.02 20:01
Titel: Windowspfad rausbekommen?
Hi Leute,
wie bekomme ich:
1. den Pfad, wo Windows installiert ist raus.Z.B bei Partition ändert sich ja das Laufwerk oder anderer Installationspfad.
2. Wie bekommt man die Windowssysteminformationen raus:
Betriebssystem(ggf. Adminrechte oder nicht),Arbeitsspeicher,Takt, etc.?
Bin sicher steht schon irgendwo, nur die Suche spuckts leider nicht aus.
Gruss
majolo
Horst - Di 24.09.02 20:09
Titel: Re: Windowspfad rausbekommen?
majolo hat folgendes geschrieben: |
Hi Leute,
wie bekomme ich:
1. den Pfad, wo Windows installiert ist raus.Z.B bei Partition ändert sich ja das Laufwerk oder anderer Installationspfad.
2. Wie bekommt man die Windowssysteminformationen raus:
Betriebssystem(ggf. Adminrechte oder nicht),Arbeitsspeicher,Takt, etc.?
Bin sicher steht schon irgendwo, nur die Suche spuckts leider nicht aus.
Gruss
majolo |
zu 1) lies mit GetenviromentVariable('WINDIR') einfach die Umgebungsvariable 'WINDIR' aus, dann weißt Du wo Windows installiert wurde. :roll:
zu 2) ist etwas kniffeliger. Da muss ich auch erstmal suchen. In irgend einer Toolbox habe schon mal was dazu gelesen... :nixweiss:
Gruss
Horst
DeCodeGuru - Di 24.09.02 20:10
zu 1.: GetWindowsDirectory. Hier ist nochmal ein Auszug aus der PSDK.
Zitat: |
The GetWindowsDirectory function retrieves the path of the Windows directory. The Windows directory contains such files as applications, initialization files, and help files.
This function is provided primarily for compatibility. Applications should store code in the Program Files folder and persistent data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath.
Quelltext 1: 2: 3: 4:
| UINT GetWindowsDirectory( LPTSTR lpBuffer, // buffer for Windows directory UINT uSize // size of directory buffer ); |
Parameters
lpBuffer
[out] Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this function is C:\Windows. If the system was installed in the root directory of drive C, the path retrieved is C:\.
uSize
[in] Maximum size of the buffer specified by the lpBuffer parameter, in TCHARs. This value should be set to MAX_PATH+1 to allow sufficient space for the path and the null terminator.
Return Values
If the function succeeds, the return value is the length of the string copied to the buffer, in TCHARs, not including the terminating null character.
If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
|
zu 2.:
Wenn du den Arbeitsspeicher auslesen willst, kannste ja mit folgendem Code experimentieren:
Quelltext
1: 2: 3: 4: 5: 6: 7: 8:
| procedure TForm1.Button1Click(Sender: TObject); var MemoryStatus: TMemoryStatus; begin MemoryStatus.dwLength := SizeOf(MemoryStatus); GlobalMemoryStatus(MemoryStatus); Label1.Caption := IntToStr((MemoryStatus.dwTotalPhys div 1024)-(MemoryStatus.dwAvailPhys div 1024)); end; |
Admin-Rechte habe ich ehrlich gesagt im Moment keine Idee bzw. bin mir bei einer Idee nicht sicher. Werde da nochmal nachgucken und dann nochmal posten. Wenn du noch die CPU-Taktfrequenz rausbekommen willst, da gibt es im Netz sehr viele Codes. Soweit ich weiss, kann man das dann mit nem Assemblercode machen. Such einfach mal in Google oder im Swissdelphicenter. Ansonsten kannste für so Einstellungen aller Desktopauflösung, Icongröße oder sowas noch GetSystemMetrics verwenden.
Na ja, ich hoffe, ich konnte dir wenigstens etwas helfen.
DeCodeGuru - Di 24.09.02 20:12
Titel: Re: Windowspfad rausbekommen?
Horst hat folgendes geschrieben: |
zu 1) lies mit GetenviromentVariable('WINDIR') einfach die Umgebungsvariable 'WINDIR' aus, dann weißt Du wo Windows installiert wurde. :roll: |
Oder so :wink:
majolo - Di 24.09.02 20:41
Danke Luckie, dein tutorial ist wirklich gut, damit ist mir schon sehr viel geholfen.
@andere: Den Windowspfad habe ich irgendwie mit euren Beschreibungen noch nicht rausbekommen.
Gruss
majolo
Delete - Di 24.09.02 20:46
Tutorial? :shock:
SysInfo ist ein Programm und soweit ich mich erinnern kann weitgehend ohne Kommentare :!:
Und wenn du dir mal meine Sourcen etwas genauer angekuckt hättest, dann hättets du in der Unit
WinInfo.pas folgendes gefunden:
Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| function GetWinDir: String; const UNLEN = MAX_PATH; var Size: DWORD; begin Size := UNLEN + 1; SetLength(Result, Size); if GetWindowsDirectory(PChar(Result), Size) <> 0 then SetLength(Result, Size - 1) else Result := ''; end; |
Alles andere steht da auch drin.
majolo - Di 24.09.02 20:55
Sorry,habe mich falsch ausgedrückt.Der Code von dir Luckie ist schon sehr erklärend.Deshalb sage ich ja mit deinem Code ging es. Mit dem der anderen habe ich es nicht geschafft.Sollte eigentlich ein Lob an dich sein. :wink: Den anderen auch Danke
Gruss
majolo
Delete - Mi 25.09.02 08:06
DeCodeGuru hat folgendes geschrieben: |
Admin-Rechte habe ich ehrlich gesagt im Moment keine Idee bzw. bin mir bei einer Idee nicht sicher. |
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:
| function GetAdminSid: PSID; const SECURITYNTAUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5)); SECURITYBUILTINDOMAINRID: DWORD = $00000020; DOMAINALIASRIDADMINS: DWORD = $00000220; begin Result := nil; AllocateAndInitializeSid(SECURITYNTAUTHORITY, 2, SECURITYBUILTINDOMAINRID, DOMAINALIASRIDADMINS, 0, 0, 0, 0, 0, 0, Result); end;
function IsAdmin: LongBool; var TokenHandle : THandle; ReturnLength : DWORD; TokenInformation : PTokenGroups; AdminSid : PSID; Loop : Integer; wv : TOSVersionInfo; begin ZeroMemory (@wv,sizeof(TOSVersionInfo)); wv.dwOSVersionInfoSize := sizeof(TOSVersionInfo); GetVersionEx(wv);
Result := (wv.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);
if(wv.dwPlatformId = VER_PLATFORM_WIN32_NT) then begin TokenHandle := 0; if OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, TokenHandle) then try ReturnLength := 0; GetTokenInformation(TokenHandle, TokenGroups, nil, 0, ReturnLength); TokenInformation := GetMemory(ReturnLength); if Assigned(TokenInformation) then try if GetTokenInformation(TokenHandle, TokenGroups, TokenInformation, ReturnLength, ReturnLength) then begin AdminSid := GetAdminSid; for Loop := 0 to TokenInformation^.GroupCount - 1 do begin if EqualSid(TokenInformation^.Groups[Loop].Sid, AdminSid) then begin Result := True; break; end; end; FreeSid(AdminSid); end; finally FreeMemory(TokenInformation); end; finally CloseHandle(TokenHandle); end; end; end; |
Anwendung:
Delphi-Quelltext
1: 2:
| if(not(isAdmin)) then ShowMessage('Komm wieder, wenn du Admin geworden bist!'); |
Euer Dank für die Funktion geht an NicoDE. :)
Moderiert von
Tino: Code- durch Delphi-Tags ersetzt.
LCS - Mi 25.09.02 08:27
Hi Mathias
Obercool, danach hab ich auch schon lange gesucht :D
Gruss Lothar
Delete - Mi 25.09.02 11:32
Ist auch genauso in der WinIfo.pas drin von meinem Programm.
Delete - Mi 25.09.02 12:39
Damit ist wohl bewiesen, dass ich mir das Programm nicht angeguckt habe? :oops: Na ja, man kann sich ja nicht um alles kümmern ... :roll:
Entwickler-Ecke.de based on phpBB
Copyright 2002 - 2011 by Tino Teuber, Copyright 2011 - 2025 by Christian Stelzmann Alle Rechte vorbehalten.
Alle Beiträge stammen von dritten Personen und dürfen geltendes Recht nicht verletzen.
Entwickler-Ecke und die zugehörigen Webseiten distanzieren sich ausdrücklich von Fremdinhalten jeglicher Art!