views:

52

answers:

2
+1  Q: 

Registry Problem

I made a launcher for my game server. (World of Warcraft) I want to get the installpath of the game, browsed by the user. I'm using this code to browse, and get the installpath, then set some other strings from the installpath string, then just strore in my registry key.

using System;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
using System.IO;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string InstallPath, WoWExe, PatchPath;
        private void Form1_Load(object sender, EventArgs e)
        {

            RegistryKey LocalMachineKey_Existence;
            MessageBox.Show("Browse your install location.", "Select Wow.exe");
            OpenFileDialog BrowseInstallPath = new OpenFileDialog();
            BrowseInstallPath.Filter = "wow.exe|*.exe";
            if (BrowseInstallPath.ShowDialog() == DialogResult.OK)
            {
                InstallPath = System.IO.Path.GetDirectoryName(BrowseInstallPath.FileName);
                WoWExe = InstallPath + "\\wow.exe";
                PatchPath = InstallPath + "\\Data\\";

                LocalMachineKey_Existence = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\ExistenceWoW");
                LocalMachineKey_Existence.SetValue("InstallPathLocation", InstallPath);
                LocalMachineKey_Existence.SetValue("PatchPathLocation", PatchPath);
                LocalMachineKey_Existence.SetValue("WoWExeLocation", WoWExe);
            }
        }
    }
}

The problem is: On some computer, it doesnt stores like it should be. For example, your wow.exe is in C:\ASD\wow.exe, your select it with the browse windows, then the program should store it in the Existence registry key as C:\ASD\Data\ but it stores like this: C:\ASDData , so it forgots a backslash :S

Look at this picture:

http://img21.imageshack.us/img21/2829/regedita.jpg

My program works cool on my PC, and on my friends pc, but on some pc this "bug" comes out :S I have windows 7, with .NEt 3.5 Please help me.

+1  A: 

Can you debug and see what InstallPath contains?

Try it with Path.Combine instead of string concatenation, e.g.:

WowExe = Path.Combine(InstallPath, "wow.exe");
PatchPath = Path.Combine(InstallPath, @"\Data\");
Paolo
While debuging:InstallPath : "C:\\Program Files\\Games\\World of Warcraft 3.3.3a\\"PatchPath:"C:\\Program Files\\Games\\World of Warcraft 3.3.3a\\Data\\"It seems on my computer it works fine, but on some others, its dont, Its weird that the same code works different on different PCs.I tryed your snippet, and it's doing the same thing, so I'll use it, maybe it works on my friend's computer.It's still a mystery for me, what happens here...THank for the answer!
Dominik
A: 

I would suggest to add some logging, to see whats the difference when the program runs at your computer and then at the computer, where it doesn't do what's expected.

Nightingale7
Ye, I wanted to implent a logging system, I'll do this, thanks :)
Dominik