Mads Mads - 10 months ago 88
C# Question

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()){

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


Answer Source

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


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.