Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing a registry string containing quotes

I have a registry string that contains double quotes that I have to edit. I know the \" ignores the quotes or whatever. I tried a verbatim string literal but that gave me 30+ errors. Anyone have any suggestions? Heres the block of code:

    RegistryKey mavroKey = Registry.LocalMachine;
    RegistryKey mavbridgeKey = mavroKey.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\MavBridge\\", true);
    mavbridgeKey.SetValue("ImagePath", " ", RegistryValueKind.String);
    mavbridgeKey.Close();

The string value is

    "C:\Mavro\MavBridge\Server\MavBridgeService.exe" /service /data "..\Data"

Thanks Trevor Heins

like image 420
heinst Avatar asked Jul 01 '26 22:07

heinst


1 Answers

When using a verbatim string, and you want to use quotes, you just need to type them twice:

@"""C:\Mavro\MavBridge\Server\MavBridgeService.exe"" /service /data ""..\Data"""

when using a normal string, you can use \" to include a quote, and \\ to include a backslash:

"\"C:\\Mavro\\MavBridge\\Server\\MavBridgeService.exe\" /service /data \"..\\Data\""
like image 141
Botz3000 Avatar answered Jul 03 '26 11:07

Botz3000