edh Posted July 20, 2023 Share Posted July 20, 2023 We need to run some commands that include " within the command. For example, using this command to disable the system screensaver in the registry: reg delete "HKEY_CURRENT_USER\Control Panel\Desktop" /v scrnsave.exe /f The trouble is that the Windows registry has spaces in some of it's paths, despite going to the effort of replacing spaces with underscores in HKEY_CURRENT_USER. To get around the spaces you have to use " within the command but if you use these commands within ShellExecute() it will fail as the extra speech marks will interfere with the command being parsed. Therefore, my question is, can you replace " with some kind of control character within a ShellExecute command? Or is there another way of doing this? Would the command be loaded into a variable and then parsed somehow? Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted July 21, 2023 Share Posted July 21, 2023 In DAQFactory ' and " are interchangeable, though they still have to be used in pairs. So, you could do: system.shellExecute("reg",'delete "HKEY_CURRENT_USER\Control Panel\Desktop" /v scrnsave.exe /f') or something like that. Notice how the first string, "reg" uses double quotes, but the second one I used single quotes to define the string. The double quotes inside this string are processed as double quote characters in the string. As mentioned, you have to use them in pairs: "abc" and 'abc' result in the same string. "abc' is invalid. "abc'def'abc" results in a string: abc'def'abc while 'abc"def"abc' results in the string: abc"def"abc If you need to use both ' and " inside your string, then you can concatenate up multiple strings. For example to create the string: abc'def"abc you would do: "abc'de" + 'f"abc' or something similar (you can put the + in several places. I chose between e and f to make it clearer). If you have a lot of it, its sometimes clearer to create variables: private string sq = "'" // double quote, single quote, double quote private string dq = '"' // its really hard to see, but that is a single quote, double quote then single quote private string out = "abc" + sq + "def" + dq + "abc" I rarely do this, but then you rarely need to use both so often. I am more apt to use this method with carriage return / line feed pairs: private string CRLF = chr(13) + chr(10) private out = "get data" + CRLF Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.