18. januar 2001 - 15:34Der er
14 kommentarer og 1 løsning
GetWindowsInfoNow
Hvordan kan jeg hente følgende stier fra windows:
Programmer Dokumeter Skrivebord
Det har lykkedes mig at hente følgende stier:
windows System temp
ved at gøre således:
var swin, windir : string; ilength : integer; begin {reading windows directory} ilength := 255; setlength(swin, ilength); ilength := getwindowsdirectory(pchar(swin), ilength); setlength(swin, ilength); windir := swin;
form1.caption := windir; end;
Men ved ikke hvordan jeg ellers skal gøre. Og forresten hvordan kan jeg finde ud af hvilken windows version jeg bruger og hvilken lydkort/grafikkort der er installeret.
Du skriver bare en masse rigtig kode og kompilerer det !
Nå spøg til side prøv det her :
Lave en function alla den her :
uses registry;
const { Registry key where Folder information is kept } SFolderKey = \'\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\';
function GetFolderLocation(const FolderType: string): string; { Retrieves from registry path to folder indicated in FolderType } begin with TRegistry.Create do try RootKey := HKEY_CURRENT_USER; if not OpenKey(SFolderKey, False) then { open key where shell folder information is kept. } raise ERegistryException.CreateFmt(\'Folder key \"%s\" not found\', [SFolderKey]); Result := ReadString(FolderType); { Get path for specified folder } if Result = \'\' then raise ERegistryException.CreateFmt(\'\"%s\" item not found in registry\',[FolderType]); CloseKey; finally Free; end; end;
AppData Cookies Desktop Favorites NetHood Personal My Pictures PrintHood Recent SendTo Start Menu Templates Programs Startup Local Settings Local AppData Cache History Fonts Administrative Tools
Ud over det vil jeg gerne supplere med de følgende oplysninger :
Function GetSystemDirectory : String; //------------------------------------- //The GetSystemDirectory Function retrieves the path //of the Windows system directory. The system directory //contains such files as Windows libraries, drivers, and font files. //------------------------------------- begin SetLength(Result, MAX_PATH); Windows.GetSystemDirectory(PChar(Result),MAX_PATH); SetLength(Result, Pred(Pos(#0,Result))); end;
Function GetTempPath : String; //------------------------------------- //The GetTempPath Function retrieves the path //of the directory designated for temporary files //------------------------------------- begin SetLength(Result, MAX_PATH); Windows.GetTempPath(MAX_PATH, PChar(Result)); SetLength(Result, Pred(Pos(#0,Result))); end;
Function GetTempFileName : String; //------------------------------------- //The GetTempFileName Function creates a new name for a temporary file //------------------------------------- Begin SetLength(Result,MAX_PATH); Windows.GetTempFileName(PChar(GetTempPath),\'TMP\', 0, PChar(Result)); End;
Lydkort / Grafik kort det ved jeg ikke står det ikke i registryen et sted ?
Any way Windows version, der vil jeg anbefale den følgende unit :
unit UnitOSVerInfo;
interface
uses Windows;
Const //: flag in bwSuiteMask - Microsoft BackOffice components are installed. VER_SUITE_BACKOFFICE = $00000004; //: flag in bwSuiteMask - Windows 2000 DataCenter Server is installed. VER_SUITE_DATACENTER = $00000080; //: flag in bwSuiteMask - Windows 2000 Advanced Server is installed. VER_SUITE_ENTERPRISE = $00000002; //: flag in bwSuiteMask - Microsoft Small Business Server is installed. VER_SUITE_SMALLBUSINESS = $00000001; //: flag in bwSuiteMask - Microsoft Small Business Server is installed with the Restrictive Client license in force. VER_SUITE_SMALLBUSINESS_RESTRICTED = $00000020; //: flag in bwSuiteMask - Terminal Services is installed. VER_SUITE_TERMINAL = $00000010;
//: constant for bwProductType - Windows 2000 Professional VER_NT_WORKSTATION = $0000001; //: constant for bwProductType - Windows 2000 domain controller VER_NT_DOMAIN_CONTROLLER = $0000002; //: constant for bwProductType - Windows 2000 Server VER_NT_SERVER = $0000003;
//: This extended version information. Because Borland did not define it, we do so here. This is because Win2000 extended it. type TOSVersionInfoEx2 = record //: This is the size of structure which we pass to Windows dwOSVersionInfoSize: UInt; //: This is the Major version dwMajorVersion: UInt; //: This is the Minor Operating System version dwMinorVersion: UInt; //: This is the build number for the Operating System dwBuildNumber: UInt; //: This is the platform ID value dwPlatformId: UInt; //: This contains additional information. On Windows NT 4.0, it will include the Service pack installed szCSDVersion: array[0..127] of AnsiChar; { Maintenance string for PSS usage } //: Windows 2000 only - Identifies the major version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the major version number is 3. If no Service Pack has been installed, the value is zero. wServicePackMajor : Word; //: Windows 2000 only - Identifies the minor version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the minor version number is 0. wServicePackMinor : Word; //: Windows 2000 only - A set of bit flags that identify the product suites available on the system. wSuiteMask : Word; //: Windows 2000 only - This indicates product type bwProductType : Byte; //: Windows 2000 only - This is for future use bwReserved : Byte; end;
//: This type indicates the Operating System on the user\'s computer in the TOSVerInfo object TWin32Type = (Win32s, WindowsNT40, Windows95, Windows95OSR2, Windows98, Windows98SE, WindowsMe, Windows2000Pro, Windows2000Server, Windows200DomainController); //: This type is used in the TInstalledSuites set and indicates a Windows 2000 TInstalledSuite = (BackOffice, DataCenter, AdvancedServer, SmallBusinessServer, SmallBusinessServerRestrictive, TerminalServices); //: This set indicates the installed suites in Windows 2000 in the TOSVerInfo object TInstalledSuites = set of TInstalledSuite;
//: This object encapsolates information about the Operating System TOSVerInfo = class(TObject) private protected FOperatingSystem : TWin32Type; FInstalledSuites : TInstalledSuites; FServicePack : String; FMajorVersion, FMinorVersion, FBuild, FPlatFormId : Uint; function GetIsWindowsNT: Boolean; function GetOsText : String; function GetInstalledSuites : String; public Constructor Create; //: This is the operating system as we could determine it property OperatingSystem : TWin32Type read FOperatingSystem; //: This is the installed Suites on Windows 2000 or greater property InstalledSuites : TInstalledSuites read FInstalledSuites; //: This is the service pack for Windows NT 4.0 or Windows 2000 property ServicePack : String read FServicePack; //: This is the major version from the GetVersionEx Win32 API call property MajorVersion : UInt read FMajorVersion; //: This is the minor version of the GetVersionEx Win32 API call property MinorVersion : UInt read FMinorVersion; //: This is the build number from the GetVersionEx Win32 API call property Build : UInt read FBuild; //: This is the platform ID from the GetVersionEx Win32 API call property PlatFormId : UInt read FPlatFormId; //: This returns True if the platform is WindowsNT 4.0 or Win32s - This is needed because some accessibility functions are not supported on those platforms property IsWindowsNT40 : Boolean read GetIsWindowsNT; //: This returns a text notation of the FOperatingSystem flag property OsText : String read GetOsText; //: This returna a teext notationof the FInstalledSuites flag property InstalledSuitesAsText : String read GetInstalledSuites; end;
function GetVersionEx2(var lpVersionInformationEx: TOSVersionInfoEx2): BOOL; stdcall;
var Ver : TOSVerInfo;
implementation
{ TOSVerInfo }
uses SysUtils;
function TOSVerInfo.GetOsText: String; begin result := \'Operation System not detected\'; case FOperatingSystem of Win32s : result := \'Win32s\'; WindowsNT40 : result := \'Windows NT 4.0\'; Windows95 : result := \'Windows 95\'; Windows95OSR2 : result := \'Windows 95 OEM Service Release 2\'; Windows98 : result := \'Windows 98\'; Windows98SE : result := \'Windows 98 Second Edition\'; WindowsMe : result := \'Windows Millenium Edition\'; Windows2000Pro : result := \'Windows 2000 Professional\'; Windows2000Server : result := \'Windows 2000 Server\'; Windows200DomainController : result := \'Windows 2000 Domain Controller\'; end; end;
constructor TOSVerInfo.Create; var VerInfo : TOSVersionInfoEx2; begin inherited Create; VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); GetVersionEx2(VerInfo); if VerInfo.dwMajorVersion >= 5 then {Windows 2000, use extended call} begin VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfoEx2); GetVersionEx2(VerInfo); case VerInfo.bwProductType of VER_NT_WORKSTATION : FOperatingSystem := Windows2000Pro; VER_NT_DOMAIN_CONTROLLER : FOperatingSystem := Windows200DomainController; VER_NT_SERVER : FOperatingSystem := Windows2000Server; end; if VerInfo.wSuiteMask and VER_SUITE_BACKOFFICE = VER_SUITE_BACKOFFICE then FInstalledSuites := FInstalledSuites + [BackOffice]; if VerInfo.wSuiteMask and VER_SUITE_DATACENTER = VER_SUITE_DATACENTER then FInstalledSuites := FInstalledSuites + [DataCenter]; if VerInfo.wSuiteMask and VER_SUITE_ENTERPRISE = VER_SUITE_ENTERPRISE then FInstalledSuites := FInstalledSuites + [AdvancedServer]; if VerInfo.wSuiteMask and VER_SUITE_SMALLBUSINESS = VER_SUITE_SMALLBUSINESS then FInstalledSuites := FInstalledSuites + [SmallBusinessServer]; if VerInfo.wSuiteMask and VER_SUITE_SMALLBUSINESS_RESTRICTED = VER_SUITE_SMALLBUSINESS_RESTRICTED then FInstalledSuites := FInstalledSuites + [SmallBusinessServerRestrictive]; if VerInfo.wSuiteMask and VER_SUITE_TERMINAL = VER_SUITE_TERMINAL then FInstalledSuites := FInstalledSuites + [TerminalServices]; if (VerInfo.wServicePackMajor <> 0) or (VerInfo.wServicePackMinor <> 0) then FServicePack := Format(\'Service Pack %d.%d\',[VerInfo.wServicePackMajor, VerInfo.wServicePackMinor]); end else begin {is this WIndows 95, 98, Me, or NT 40} if VerInfo.dwMajorVersion > 3 then begin if VerInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then begin FOperatingSystem := WindowsNT40; FServicePack := VerInfo.szCSDVersion; end else begin {mask off junk} VerInfo.dwBuildNumber := VerInfo.dwBuildNumber and $FFFF;
if VerInfo.dwMinorVersion >= 90 then FOperatingSystem := WindowsMe else if VerInfo.dwMinorVersion >= 10 then begin {Windows 98} if VerInfo.dwBuildNumber >= 2222 then FOperatingSystem := Windows98SE else FOperatingSystem := Windows98; end else begin {Windows 95} if VerInfo.dwBuildNumber >= 1000 then FOperatingSystem := Windows95OSR2 else FOperatingSystem := Windows95; end; end; end else begin FOperatingSystem := Win32s; end; end; FMajorVersion := VerInfo.dwMajorVersion; FMinorVersion := VerInfo.dwMinorVersion; FBuild := VerInfo.dwBuildNumber; FPlatFormId := VerInfo.dwPlatformId; end;
function TOSVerInfo.GetIsWindowsNT: Boolean; begin Result := (FOperatingSystem = WindowsNT40) or (FOperatingSystem = Win32s); end;
function TOSVerInfo.GetInstalledSuites: String; begin result := \'\';
if BackOffice in FInstalledSuites then if result <> \'\' then Result := \', Microsoft BackOffice\' else Result := \' Microsoft BackOffice\';
if DataCenter in FInstalledSuites then if result <> \'\' then Result := \', DataCenter Server\' else Result := \' DataCenter Server\';
if AdvancedServer in FInstalledSuites then if result <> \'\' then Result := \', Advanced Server\' else Result := \' Advanced Server\';
if SmallBusinessServer in FInstalledSuites then if result <> \'\' then Result := \', Small Business Server\' else Result := \' Small Business Server\';
if SmallBusinessServerRestrictive in FInstalledSuites then if result <> \'\' then Result := \', Small Business Server with Restrictive Client License\' else Result := \' Small Business Server with Restrictive Client License\';
if TerminalServices in FInstalledSuites then if result <> \'\' then Result := \', Terminal Services\' else Result := \' Terminal Services\';
if result = \'\' then result := \'(none)\'; end;
function GetVersionEx2; external kernel32 name \'GetVersionExA\';
initialization ver := TOSVerInfo.Create; finalization ver.Free; ver := nil; end.
Windows.getversionex kan ikke teste for Windows 2000 og da slet ikke for hvilken tpye af Windows 2000 det er ....
Den jeg har laver ligger du bare i en unit for sig selv .... Inkulderer den i din uses klausul i en anden unit. inde fra den sidste unit har du en variable synlig der hedder ver den kalder du bare metoder på direkte unden nogen former for noget som helst ... Nemmere kan det da ikke blive .... Prøv det nu inden du brokker dig ..
procedure TForm1.Button1Click(Sender: TObject); var Hest : TOSVersionInfo; begin Hest.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); GetVersionEx(Hest); caption := Format(\'Windows %d.%d %s\',[Hest.dwMajorVersion, Hest.dwMinorVersion, Hest.szCSDVersion]) og så er det blot at gå i gang med variablerne på hest .... end;
Jeg vil lige vise dig hvor let du kommer over det med men unit ...
Snowball >> Mod din (?) forventning ejer jeg ikke en hest. Grunden til at jeg kalder mine variabler for hest, er at det er så rasende godt debug ord ....
Det er en gammel vane .. Ud over det så kan der gå hest i det hele. Et lokale kan lugte af brugt hest, eller det hele kan bare være noget hest endag ....
Jens B
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.