开发者

Registry Problem

开发者 https://www.devze.com 2022-12-31 01:55 出处:网络
I made a launcher for m开发者_StackOverflow社区y game server. (World of Warcraft) I want to get the installpath of the game, browsed by the user.

I made a launcher for m开发者_StackOverflow社区y 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.


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\");
0

精彩评论

暂无评论...
验证码 换一张
取 消