I am trying to get the path to AcroRd32.exe by invoking the following code:
public static string acrobatPath = Registry.GetValue(@"HKEY_CLASSES_ROOT\Applications\AcroRD32.exe\shell\Read\command", "", 0).ToString();
What I receive is the right value:
"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" "%1"
but I want only the path to AcroRd32.exe without “%1”.
I could now use the split command:
public static string acrobatPath = Registry.GetValue(@"HKEY_CLASSES_ROOT\Applications\AcroRD32.exe\shell\Read\command", "", 0).ToString();
string[] split = new string[2];
split = acrobatPath.Split('"');
// mask path with ""
acrobatPath = "\"" + split[1] + "\""; //get only path
but the value acrobatPath cannot be changed because of static attribute.
I also cannot use substr() because path can differ e.g. if there is no parameter at the end (“%1”).
How can I extract the path and set the static variable in one go?
Use static constructor for your class, and do all the work for string manipulation there.