Search code examples
c#.netregistrystartupboot

Extract filepath from arbitrary string


I've been attempting to list all filepaths for programs that start on boot. I encountered the following data

Rundll32.exe shell32.dll, ShellExec_RunDLL C:\Users\Name\AppData\Roaming\Oracle\JavaUpdate.exe

"C:\Program Files (x86)\Steam\steam.exe" -silent

This data is from the registry \HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run, obtained using following code

foreach(var valueName in registryKey.GetValueNames()){
  bootItems.Add(registryKey.GetValue(valueName);
}

Which solution could extract the path from both? I've attempted to use the following regular expression and variations without any luck.

"^\"([^\"]*)\".*$"

Solution

  • If they only ever look like that then this regex will do the job:

    \b.:\\.+?.exe\b
    

    It matches any character followed by a colon and a slash,followed by any text that then ends with .exe where the start/end is either a word break or a start/end of line.