Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetCurrentProcessExecutionOption should allow a process name to be passed in #379

Open
JeffMill opened this issue Oct 6, 2023 · 1 comment
Labels
feature-request New feature or request

Comments

@JeffMill
Copy link

JeffMill commented Oct 6, 2023

Current code appends the process name from GetModuleFileNameW:

    // Lookup a DWORD value under HKLM\...\Image File Execution Options\<current process name>
    inline DWORD GetCurrentProcessExecutionOption(PCWSTR valueName, DWORD defaultValue = 0)
    {
        auto filePath = wil::GetModuleFileNameW<wil::unique_cotaskmem_string>();
        if (auto lastSlash = wcsrchr(filePath.get(), L'\\'))
        {
            const auto fileName = lastSlash + 1;
            auto keyPath = wil::str_concat<wil::unique_cotaskmem_string>(LR"(SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\)",
                fileName);

My code (for reasons) needs to use a value different from a process name that hosts my DLL and other DLLs, so I'd like a unique identifier. I realize this is probably overloading the intention of this method, but it would be convenient to have:

    inline DWORD GetCurrentProcessExecutionOption(PCWSTR valueName, DWORD defaultValue = 0, PCWSTR fileNameOverride = nullptr)
    {
      if (fileNameOverride) { fileName = filePathOverride; }
      else { /* existing filePath/lastSlash code */ }
       ...
    }
@dunhor dunhor added the feature-request New feature or request label Oct 9, 2023
@ChrisGuzak
Copy link
Member

PR welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants