1
votes
c# - IconPath not exsist - Stack Overflow
Asked
Viewed 57 times
1

When I'm searching for a IsSystemSoundsSession I can't find the IconPath provided. On my system (Windows 10 1909). I'm getting IconPath @%SystemRoot%\\System32\\AudioSrv.Dll,-203 This file doesn't exist. (yes I expanded the variable for this, but that resolves to @C:\Windows\System32\AudioSrv.dll (notice the '@').

Found a solution. The file that I'm searching for is located in C:\Windows\System32\AudioSrv.dll. Notice how there is an @ part as first character? It looks like that is the problem. Not sure if this is a problem with NAudio or Windows API.

IconPath System Sound

Code to retrieve the IconPath

            MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
            var devices = enumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active);

            foreach (var device in devices)
            {
                var sessions = device.AudioSessionManager.Sessions;
                
                for (int i = 0; i < sessions.Count; i++)
                {
                    var session = sessions[i];
                    var iconPath = session.IconPath;
                    // iconPath == '@%SystemRoot%\\System32\\AudioSrv.Dll,-203'
                }
            }
        }
    0

    You could hardcode c:\windows\system32 instead, but actually you don't really know that location. That is where the environment variable %systemroot% comes in.

    Your @ string is a path name containing this environment variable. You cannot open it as a file, first the variable need be resolved, consider:

     string trueIconPath = Environment.ExpandEnvironmentVariables( iconPath.Substring(1))
    

    The outcome will probably be: c:\windows\system32\AudioSrv.dll as intended for your machine.. on my PC it would become f:\cfg1\Windows\System32\AudioSrv.dll

    Refer for more info: https://docs.microsoft.com/en-us/dotnet/api/system.environment.expandenvironmentvariables?view=netcore-3.1

    2
    • I know that I can expand the Variable, and remove the 1ste character. But when I ask the Speaker IconPath I get a valid Path. It looks like that '@' character has a special meaning, but can't find that anywhere what it is. I will edit my answer to clarify that I know of the expanded enviormentvariables :)
      – P-Storm
      Jun 22 2020 at 6:59
    • I have no idea why the @ is there P-Storm, suppose the filename is marked because it contains environment variable(s) ? Your complaint was the filename as given did not open properly. I have answered your question, because you suggest in your opening, that hardcoding c:\windows\system32 is a solution. It is not. Please dont change your question on the fly.. use the Edit option only to change the opening text for clarification, or to denote information from answers given. Like my answer.
      – Goodies
      Jun 22 2020 at 12:21

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

    Not the answer you're looking for? Browse other questions tagged or ask your own question.

     
    1

    1 Answers

    0
    votes

    You could hardcode c:\windows\system32 instead, but actually you don't really know that location. That is where the environment variable %systemroot% comes in.

    Your @ string is a path name containing this environment variable. You cannot open it as a file, first the variable need be resolved, consider:

     string trueIconPath = Environment.ExpandEnvironmentVariables( iconPath.Substring(1))
    

    The outcome will probably be: c:\windows\system32\AudioSrv.dll as intended for your machine.. on my PC it would become f:\cfg1\Windows\System32\AudioSrv.dll

    Refer for more info: https://docs.microsoft.com/en-us/dotnet/api/system.environment.expandenvironmentvariables?view=netcore-3.1