-2

My program retrieves a value a registry key(a path to GTA's folder). I'm using the following code to retrieve it:

private static string PathName
{
    get
    {
        using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\SAMP"))
        {
            return (string)registryKey.GetValue("gta_sa_exe");
        }
    }
}

Anyhow, it retrieves it with double backslashes, and I'm trying to replace these by using the following code:

string installdirectory = path.Replace(@"\\", @"\");

System.Diagnostics.Process.Start(installdirectory + " -c -n " + playerinfo[0] + " -h 127.0.0.1 -p 7777");`

but it remains unchanged, can anyone help me out here?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Nutz
  • 79
  • 2
  • 11
  • If you view it in the debugger, it's going to show double backslashes. That is, the string `"foo\bar"` will be displayed as `"foo\\bar`" in the debugger. What does it look like when you display it on the console or write it to a file? – Jim Mischel Mar 15 '17 at 22:03
  • It remains unchanged because there are no double backslashes in the string retrieved. You are worrying for nothing. @JimMischel explained the _problem_ – Steve Mar 15 '17 at 22:10
  • You should use [this overload](https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx) of `Process.Start` where the arguments are separate. I suspect this is your problem. You are starting a program named "c:\installDirectory\gta_sa.exe -c -n asdf -h etc..", but your program is named simply "c:\installDirectory\gta_sa.exe". Try this instead: `Process.Start(installdirectory, "-c -n " + playerinfo[0] + " -h 127.0.0.1 -p 7777")` – Quantic Mar 15 '17 at 22:25

1 Answers1

2

There is no problem. For example, run this program:

void Main()
{
    string s = "foo\\bar";
    Console.WriteLine(s);
}

If you examine the value of s in the debugger, you'll see "foo\\bar". But when output, you will see "foo\bar".

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351