david_navigator 12 Posted February 24, 2021 Is there a better way to get the list of Windows sounds as displayed in this Sounds dropdown without simply enumerating the contents of the %windir%\Media folder ? Share this post Link to post
Remy Lebeau 1396 Posted February 24, 2021 3 hours ago, david_navigator said: Is there a better way to get the list of Windows sounds as displayed in this Sounds dropdown without simply enumerating the contents of the %windir%\Media folder ? What's wrong with enumerating that folder? That is likely what the dialog is doing. Why do you expect there to be an API that provides that list? Not everything in a system UI has a dedicated API behind it. Share this post Link to post
KodeZwerg 54 Posted February 24, 2021 There might be a better way. You can enumerate over registry. HKEY_CURRENT_USER\AppEvents\Schemes Then you know wich sound belong to wich action. If I missunderstood question, I am sorry. Share this post Link to post
david_navigator 12 Posted February 24, 2021 (edited) 1 hour ago, Remy Lebeau said: What's wrong with enumerating that folder? That is likely what the dialog is doing. Why do you expect there to be an API that provides that list? Not everything in a system UI has a dedicated API behind it. Nothing. I just didn't want to do that IF there was an API that was the prefered method, especially as I couldn't find any documentation as to whether the folder name is localized in none English Windows. Edited February 24, 2021 by david_navigator Share this post Link to post
Guest Posted February 24, 2021 5 hours ago, david_navigator said: I just didn't want to do that IF there was an API that was the prefered method, for well, with just only line and a "ListBox" you can take all "wav" files used by MSWindows! MSWindows 10 64bits RAD Studio 10.3.3 Arch VCL or FMX Project uses System.IOUtils; procedure TForm1.btn_MSWindowsMediaFilesClick(Sender: TObject); begin { TFilterPredicate = reference to function(const Path: string;const SearchRec: TSearchRec): Boolean; } { TSearchOption.soTopDirectoryOnly or TSearchOption.soAllDirectories } // ListBox1.Items.Clear; // ListBox1.Items.AddStrings( { } TDirectory.GetFiles('C:\Windows\Media', '*.wav', TSearchOption.soAllDirectories { , TFilterPredicate } ) { } ); end; or scroll through the "Computador\HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default" key in your Registry and select what you want to find, for example!or hug Share this post Link to post
KodeZwerg 54 Posted February 26, 2021 (edited) procedure GetRegistrySounds; var phkResult: HKEY; dwIndex: DWORD; HResult: Longint; lpName: LPWSTR; SubKeyNames: TStringList; i: Integer; Len: Longint; Buf: array[0..1023] of Char; dwResult: DWORD; ResultString: string; begin SubKeyNames := TStringList.Create; try dwIndex := 0; lpName := StrAlloc(1024); HResult := RegOpenKeyEx(HKEY_CURRENT_USER, PChar('AppEvents\Schemes\Apps\.Default'), 0, KEY_READ, phkResult); if (HResult = ERROR_SUCCESS) then begin while (HResult = ERROR_SUCCESS) do begin HResult := RegEnumKey(phkResult, dwIndex, lpName, 1024); if (HResult = ERROR_SUCCESS) then begin SubKeyNames.Add(lpName); Inc(dwIndex); end; end; RegCloseKey(phkResult); end; StrDispose(lpName); for i := 0 to (SubKeyNames.Count - 1) do begin if (RegOpenKeyEx(HKEY_CURRENT_USER, PChar('AppEvents\Schemes\Apps\.Default\' + SubKeyNames[i] + '\.Current'), 0, KEY_READ, phkResult) = ERROR_SUCCESS) then begin Len := 1024 * SizeOf(Char); case RegQueryValueEx(phkResult, PChar(''), nil, nil, PByte(@Buf[0]), @Len) of ERROR_SUCCESS: SetString(ResultString, Buf, Len div SizeOf(Char) - 1); ERROR_MORE_DATA: begin SetLength(ResultString, Len div SizeOf(Char) - 1); if (RegQueryValueEx(phkResult, PChar(''), nil, nil, PByte(ResultString), @Len) = ERROR_SUCCESS) then SetLength(ResultString, Len div SizeOf(Char) - 1) else ResultString := ''; end; end; RegCloseKey(phkResult); if (ResultString <> '') then begin dwResult := ExpandEnvironmentStrings(PChar(ResultString), buf, 1024); if (dwResult <> 0) then ResultString := string(buf); // here we have a result to work with Form1.Memo1.Lines.Add(ResultString); end; end; end; finally SubKeyNames.Free; end; end; Edited February 26, 2021 by KodeZwerg Share this post Link to post
KodeZwerg 54 Posted February 26, 2021 (edited) Above code will readout registry data. Modify Form1.Memo1 to your needs. //edit Code aint perfect designed, just a working release. Have fun 🙂 Edited February 26, 2021 by KodeZwerg Share this post Link to post
Guest Posted February 26, 2021 (edited) 37 minutes ago, KodeZwerg said: Above code will readout registry data. better dont trust the Registry as "right"! --> somebody can dont have it as your...you see? an user, can dont have previlegies on Registry key, for example, if a user is very restrict for use just some part of your system at all on MSWin we can have more than an user, and each user can have some restriction on system! better check the "real files on disk" - using a folder default or specific for this task, can be the "key" for example, an user can dont have access to "user folder of other user", etc.. if the files exist, then, just fill the list (TStringList, TList, and sub-classes) - of course, if the files is "corrupted"... nothing to do with it! hug Edited February 26, 2021 by Guest Share this post Link to post
KodeZwerg 54 Posted February 26, 2021 (edited) My bad. Your best. Peace Edited February 26, 2021 by KodeZwerg 1 Share this post Link to post
Guest Posted February 26, 2021 3 hours ago, KodeZwerg said: My bad. Your best. Peace no. no. no. your app, your code! what be better for you! hug Share this post Link to post